From patchwork Tue Feb 27 13:32:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 776195 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp155797wro; Tue, 27 Feb 2024 05:34:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXQIGYew6Ly0oPfv7R5XK5g3OGxbFBL1KwUYjTnI/psJkMCral85ab+RCnaC/RVhHRIagfSNN152EAjTePCMgOW X-Google-Smtp-Source: AGHT+IHYhMofjmBCQNFQD03KoeRMFHpO3AD/owDouGnKblGk6BIYbygYdU6Tn0dm4AeGlSGDG9ch X-Received: by 2002:a81:e90a:0:b0:607:ca2e:f23e with SMTP id d10-20020a81e90a000000b00607ca2ef23emr2212399ywm.30.1709040869759; Tue, 27 Feb 2024 05:34:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709040869; cv=none; d=google.com; s=arc-20160816; b=HlFkzDz7mLEnB18K6FHXn03FkOT6JDkZs2HDY2KTWKbBKK5AMx5CPLAr0ygfe3Xpnk hscrkfSleaNeCWsA/dh39PAuAOvvTRiFNNJ6vBA2cc4/f8spVkpXrYqRh4jAaaxKFfr+ 8T/mi1fFd0r0uRbLRHuPfePcO2g3SlPcokWN28OHc+cJc3TkY6tgFTpkHWBC9Hn3TBij kYa99+FOcPa3fZJyVCU9IlWTb+gm15NOSXznQCQv8r37Z4dCRvCjIkdmw2dNQCD9CyxH zheS3l2e+fkXv8Oa2oVAbPkXoJR9uGuvNMOLFJjF9abYzqvHAXWVI09sOIAULD8N12km zmiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=no1yxF9QVzDWCiPK1PcrjBYtl68uz4bzwyJtwJFIo0s=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=B6v59j/JsAbc50CtAiFujNROKrgy0UYsXWJ/GF2PWxxNqHk1pELVCRxYE+19Wz5t+X f1dDT0lAh+GdZf+Y5MhRj1txZPj9e19Y19YqUZBmoCR8edSPZSG7Uu3np4wbtyaRaqUr CzcMdRSicH4JqB8lE+O40n4isqNwDxpb849oHOPDTxOBkfLmsUy14wj7JDSNKF6jYY4m z+AP+dyV8MTN4T+F2xFe8vUqfcLV5g9Z6ZYqEoKwoIS0/lAVofr3HlOT31PVBgOKJOro xqssoU7mOxJejYNYL9IkZvOdr1uKmP7U1N0LVMYv/B6taty7H9AEvXz4mgqQI3LopPVb vK5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qAkMtt9Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g17-20020ac84691000000b0042e6f32da95si7113280qto.711.2024.02.27.05.34.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 05:34:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qAkMtt9Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rexaX-0000oU-UZ; Tue, 27 Feb 2024 08:33:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rexaI-0000jU-Ny for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:27 -0500 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rexaG-0002rk-U9 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:26 -0500 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2d27fef509eso38015811fa.3 for ; Tue, 27 Feb 2024 05:33:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709040803; x=1709645603; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=no1yxF9QVzDWCiPK1PcrjBYtl68uz4bzwyJtwJFIo0s=; b=qAkMtt9YeVMkY7NqDuwUEFs1X/walUnQBlsN5wXcN/owHivp1GrrMQlRLjLGxmYb5E Z3kvBbReG336hskZ7QTsnpaHaPbzDlwGjnnLoZZe/LqQqwVHMROAdRPpnbGtmVxMjm6z 8VMN6milsiExrbaW6rYzYb5aZk7fyBUfZ6pEaTcRbLSgDC0Anh4ZNuf7WTxmHwdc4Abw En4m0+IsaUC/1zgjIzQJiaB5RkX7pBBwkhslWtcH5lGCGhqS+JkI4t0pP42/Xt1KWikr fPl0gyfF+VZ34hOWNb+ZGXlar6oHYUbEmeFg9l2enIOppFWBANKIuoYDkEazMfaaIgwF Hb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709040803; x=1709645603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=no1yxF9QVzDWCiPK1PcrjBYtl68uz4bzwyJtwJFIo0s=; b=eyXn9sg/qfBU/hirxre4sgBA//2hCKDM30DlrZUOZw/8cv0zknFi+NP+cQ/Gq4FzOQ rkr327EqcCfT5cmd7yUI6uczk/grlLEDCZfbOlKzEooM4/NcAa38KQD82gHmt0XkUXAb Fguv/qOlY4gKibC4CDcknR/hSJBseLrAqUuodL9rGvPYOFdMRmB7vkBS4kw97UQccaVi +OTIeJapzxNIwtb5/Tk/R3DJfARKPnqD1w5K5pTAc2g5b1erDrlQcHv1FqvKy6wUKRZm Ae0+6ovpclgIAaQJQDJs4CMvjkcRY129RaHRbBb5ERnPO6s2Eb3vaLgsh/kT0+dtkGlI QTjA== X-Gm-Message-State: AOJu0Yy0sygK8FvGdIIg0/kA1LvLD85BT0KjsMATR4Jf3r8MJxvonlGy maS9TlMbY1ynylEqzPNcXOR7AfIDAkqsKVZ5y1P7DBEEcqxYAMnEK16at9wdAZ14AYn3CWu1xSo r X-Received: by 2002:a05:651c:556:b0:2d2:a443:9c64 with SMTP id q22-20020a05651c055600b002d2a4439c64mr851055ljp.45.1709040801748; Tue, 27 Feb 2024 05:33:21 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i13-20020adfe48d000000b0033ae7d768b2sm11319552wrm.117.2024.02.27.05.33.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 05:33:21 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 12/45] arm/ptw: Handle atomic updates of page tables entries in MMIO during PTW. Date: Tue, 27 Feb 2024 13:32:41 +0000 Message-Id: <20240227133314.1721857-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227133314.1721857-1-peter.maydell@linaro.org> References: <20240227133314.1721857-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jonathan Cameron I'm far from confident this handling here is correct. Hence RFC. In particular not sure on what locks I should hold for this to be even moderately safe. The function already appears to be inconsistent in what it returns as the CONFIG_ATOMIC64 block returns the endian converted 'eventual' value of the cmpxchg whereas the TCG_OVERSIZED_GUEST case returns the previous value. Signed-off-by: Jonathan Cameron Message-id: 20240219161229.11776-1-Jonathan.Cameron@huawei.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/ptw.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 5eb3577bcd5..ba1a27ca2b5 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -711,8 +711,68 @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val, void *host = ptw->out_host; if (unlikely(!host)) { - fi->type = ARMFault_UnsuppAtomicUpdate; - return 0; + /* Page table in MMIO Memory Region */ + CPUState *cs = env_cpu(env); + MemTxAttrs attrs = { + .space = ptw->out_space, + .secure = arm_space_is_secure(ptw->out_space), + }; + AddressSpace *as = arm_addressspace(cs, attrs); + MemTxResult result = MEMTX_OK; + bool need_lock = !bql_locked(); + + if (need_lock) { + bql_lock(); + } + if (ptw->out_be) { + cur_val = address_space_ldq_be(as, ptw->out_phys, attrs, &result); + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + if (need_lock) { + bql_unlock(); + } + return old_val; + } + if (cur_val == old_val) { + address_space_stq_be(as, ptw->out_phys, new_val, attrs, &result); + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + if (need_lock) { + bql_unlock(); + } + return old_val; + } + cur_val = new_val; + } + } else { + cur_val = address_space_ldq_le(as, ptw->out_phys, attrs, &result); + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + if (need_lock) { + bql_unlock(); + } + return old_val; + } + if (cur_val == old_val) { + address_space_stq_le(as, ptw->out_phys, new_val, attrs, &result); + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + if (need_lock) { + bql_unlock(); + } + return old_val; + } + cur_val = new_val; + } + } + if (need_lock) { + bql_unlock(); + } + return cur_val; } /*