From patchwork Fri Sep 30 21:31:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 77184 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp514720qgf; Fri, 30 Sep 2016 14:38:29 -0700 (PDT) X-Received: by 10.55.25.29 with SMTP id k29mr9854218qkh.296.1475271509468; Fri, 30 Sep 2016 14:38:29 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x43si4241714qta.107.2016.09.30.14.38.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Sep 2016 14:38:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Vk-0003Q9-V8 for patch@linaro.org; Fri, 30 Sep 2016 17:38:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5P3-0006Zy-FX for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5P0-0006b7-NU for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:32 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:37331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5P0-0006b0-Cl for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:30 -0400 Received: by mail-wm0-x22b.google.com with SMTP id b80so66260073wme.0 for ; Fri, 30 Sep 2016 14:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fuk3B9SCoRDYETXRIDcz0iqrEkxMd2FOWKKnczQFFd0=; b=iG1fqqUd0/sQ4+qOf4t4Wig/P8Z2i1GoXyTdj4oRZ9rXCdAAwkdIUz6pS3wZNe7eKl 3aHOjwjtsdnYZmGq8DJ2O5f1OuVycxawYVWD8tjzEsnzjAhs21Yp5EtwMBRAVhE9Iu3P gP+E8vq+YJWODqZPvf7YESuzuwxgW8WHI9L/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fuk3B9SCoRDYETXRIDcz0iqrEkxMd2FOWKKnczQFFd0=; b=XBpeLfi3ND0YZOZ/LcNY9ejFmUVC5hBsPv+oNwklqi5EboJFNVbRu731Z+GhM2OiAK ZPNrhDIKjo7r8l871Pz6oYHY7qTbYeYCb8Ao8i5/DFNGT+NfaMQB++wtJKj4fPW5sBcC 2hCW5ut3EdF/ye5WMbJgUiFb6wBGCBqjUUX+7ZzaED5SPdB0cwk1w0o3O8PGEw1XBKTr 1Ip4sQPtK6/PcUVAtIRjTeRHRWlvkOwUWPX4xK/Ukh/SnoKr4O3mtqq6Mb7U4YkjSfzl kgze4Rz5l5qQpkxKu4CXNEZs1VfXLCEfLZgF/XSX5YNAausFstDlM14gCD6Ok/g7UGNg anJA== X-Gm-Message-State: AA6/9RkxsF/sf9bQw/8tDk7BP9pP8NtAIgQxomE4ap25eTUCHqzd9bca0Lljr+rdjLpOKiEM X-Received: by 10.195.10.132 with SMTP id ea4mr8322422wjd.19.1475271089727; Fri, 30 Sep 2016 14:31:29 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l6sm6048788wmg.11.2016.09.30.14.31.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 14:31:23 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 8877F3E06AA; Fri, 30 Sep 2016 22:31:18 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 30 Sep 2016 22:31:06 +0100 Message-Id: <20160930213106.20186-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160930213106.20186-1-alex.bennee@linaro.org> References: <20160930213106.20186-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22b Subject: [Qemu-devel] [PATCH v3 15/15] translate-all: mark updates to PageDesc as atomic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, serge.fdrv@gmail.com, bobby.prani@gmail.com, rth@twiddle.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Updates to the internal page table are protected by the mmap_lock. However for defined C11 semantics things that are access across threads need to accessed using at least relaxed atomics. Signed-off-by: Alex Bennée --- translate-all.c | 67 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) -- 2.9.3 diff --git a/translate-all.c b/translate-all.c index a6262ae..2d6c0e8 100644 --- a/translate-all.c +++ b/translate-all.c @@ -805,22 +805,21 @@ static inline void invalidate_page_bitmap(PageDesc *p) static void page_flush_tb_1(int level, void **lp) { int i; + PageDesc *pd = atomic_rcu_read(lp); - if (*lp == NULL) { - return; - } - if (level == 0) { - PageDesc *pd = *lp; + if (pd) { + if (level == 0) { - for (i = 0; i < V_L2_SIZE; ++i) { - pd[i].first_tb = NULL; - invalidate_page_bitmap(pd + i); - } - } else { - void **pp = *lp; + for (i = 0; i < V_L2_SIZE; ++i) { + atomic_set(&pd[i].first_tb, NULL); + invalidate_page_bitmap(pd + i); + } + } else { + void **pp = (void **) pd; - for (i = 0; i < V_L2_SIZE; ++i) { - page_flush_tb_1(level - 1, pp + i); + for (i = 0; i < V_L2_SIZE; ++i) { + page_flush_tb_1(level - 1, pp + i); + } } } } @@ -1360,7 +1359,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, /* we remove all the TBs in the range [start, end[ */ /* XXX: see if in some cases it could be faster to invalidate all the code */ - tb = p->first_tb; + tb = atomic_read(&p->first_tb); while (tb != NULL) { n = (uintptr_t)tb & 3; tb = (TranslationBlock *)((uintptr_t)tb & ~3); @@ -1968,16 +1967,15 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) the code inside. */ if (!(p->flags & PAGE_WRITE) && (flags & PAGE_WRITE) && - p->first_tb) { + atomic_read(&p->first_tb)) { tb_invalidate_phys_page(addr, 0); } - p->flags = flags; + atomic_set(&p->flags, flags); } } int page_check_range(target_ulong start, target_ulong len, int flags) { - PageDesc *p; target_ulong end; target_ulong addr; @@ -2003,28 +2001,31 @@ int page_check_range(target_ulong start, target_ulong len, int flags) for (addr = start, len = end - start; len != 0; len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { - p = page_find(addr >> TARGET_PAGE_BITS); - if (!p) { - return -1; - } - if (!(p->flags & PAGE_VALID)) { - return -1; - } + PageDesc *p = page_find(addr >> TARGET_PAGE_BITS); + if (p) { + int cur_flags = atomic_read(&p->flags); - if ((flags & PAGE_READ) && !(p->flags & PAGE_READ)) { - return -1; - } - if (flags & PAGE_WRITE) { - if (!(p->flags & PAGE_WRITE_ORG)) { + if (!(cur_flags & PAGE_VALID)) { return -1; } - /* unprotect the page if it was put read-only because it - contains translated code */ - if (!(p->flags & PAGE_WRITE)) { - if (!page_unprotect(addr, 0)) { + + if ((flags & PAGE_READ) && !(cur_flags & PAGE_READ)) { + return -1; + } + if (flags & PAGE_WRITE) { + if (!(cur_flags & PAGE_WRITE_ORG)) { return -1; } + /* unprotect the page if it was put read-only because it + contains translated code */ + if (!(cur_flags & PAGE_WRITE)) { + if (!page_unprotect(addr, 0)) { + return -1; + } + } } + } else { + return -1; } } return 0;