From nobody Tue Nov 26 10:35:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1708694087; cv=none; d=zohomail.com; s=zohoarc; b=GWl4Cxvd4tZytgHb4SYUdO3aiyla4wzkEsfGr+skPxv7ug/Ll3g/1wTaeh24qvLIORSQUnssCcgOFtUmR3sJOkoP5fzRZCbgURK8wrpeaPRRYv7NNwO+7R9sr5du6iuZH1aiZpYuVLHQX59dp1K7zeW5KkocaUG7cIZ4SeWiRpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708694087; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fnQ7i5ueTC+xlo8UAzRXXauDN9cg2kKCLhjsqVL+gjQ=; b=USKc21P/3PylFhXY67Gnep6xydxI28E0pdV4yiYgz/VSfgS0gHqUCh9tU48ZANNSZWdpuiSVhxj4r3gnveJ/R2vMI4o4RShFGQAJyvRncWFigyagtwtckGKVMs3V83+MPfYq/Qs7IWDcAlB1fe55aZ7wWoao3aWdepjub+G+vRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708694087431948.0038538974519; Fri, 23 Feb 2024 05:14:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdVNe-0005VZ-Fb; Fri, 23 Feb 2024 08:14:22 -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 1rdVJn-0002b8-UO for qemu-devel@nongnu.org; Fri, 23 Feb 2024 08:10:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdVJh-0000TA-66 for qemu-devel@nongnu.org; Fri, 23 Feb 2024 08:10:23 -0500 Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-_BmBdEPEMlSimcFuVcDmKw-1; Fri, 23 Feb 2024 08:10:13 -0500 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2d27386667eso2558301fa.2 for ; Fri, 23 Feb 2024 05:10:13 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id n22-20020a2e86d6000000b002d0acb57c89sm2563335ljj.64.2024.02.23.05.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:10:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708693814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fnQ7i5ueTC+xlo8UAzRXXauDN9cg2kKCLhjsqVL+gjQ=; b=IqXZj2NGjw+7LiegsAQ1yOGBOqVpzwWama/wKlMPUle5DD1VtmQyNYMnnCdsaCMP/RXkyO Nm7RvI7pDqaO5SJ49JBb+AKB35rdedwEcZ1Lup0CpLri/0adW6gHIH7xsuxM9tHZKmD+Zn OxrdOhZ0Gk/IjfsdcRyZ+2QZygIbVA0= X-MC-Unique: _BmBdEPEMlSimcFuVcDmKw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708693810; x=1709298610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fnQ7i5ueTC+xlo8UAzRXXauDN9cg2kKCLhjsqVL+gjQ=; b=CDd+wcUeabW/8nmcpOVx1W7of3ReSU9UZLuXbgPQ/VyPPfeQsR+JHp0FYcmpOVwE68 cND01nyNYzaMEwM42R/gMixVh5w1jnN6evzYdrBLJqkP6S9wSzV2/UZnwOg6kHLL8p52 q8aZTp7ehqHisb97/8BjroYc9kKpqDyMfmUcl2LsXQ+123gF4Gxvs4Dmjc20/jA6DiXD iBF/n6HKuS5Qt7M0dmWA8Iy1WaZtFCJIo/KOR7UtAoXivW4G9mzS9/b/eZbo43ulsYwX 2o7hKurVSsE9nMjkEBghGdXzJL9by6H+qhjW0sfAUNhtIrztAGvR8OkZekdHspDm7Zg5 c/yg== X-Gm-Message-State: AOJu0YwGfaeoPvXN32H83OJTJisdR3abjZNKW4duHYSv0eKzqxmibelE COUlPCdPZ4jfRs1Le90tG8AVCtkbo0PR+q/pmd66Q99bNsHzf74ZWybEuGhmYNpmNjsz8ed/AzJ y7ca/klSsVMY3OaCI/AAuzCl5gBgMmkcOrFQ67uKXsoXr9Gj12qMo36SBYhPlbqkKVpzjPrw3Hr bZCg5OBy5Mivz2lSQb8LLRIqfSNbydpb5c7hyH X-Received: by 2002:a2e:a78e:0:b0:2d2:39ab:eee1 with SMTP id c14-20020a2ea78e000000b002d239abeee1mr1705204ljf.32.1708693810464; Fri, 23 Feb 2024 05:10:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IElP3c5/uDGrDGmeAi97RUXbnQQgyKcu1VdqWxjWVIWvgYhFWLy7diaD3riy6szGHec702ezw== X-Received: by 2002:a2e:a78e:0:b0:2d2:39ab:eee1 with SMTP id c14-20020a2ea78e000000b002d239abeee1mr1705178ljf.32.1708693810148; Fri, 23 Feb 2024 05:10:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, mcb30@ipxe.org Subject: [PATCH v2 7/7] target/i386: leave the A20 bit set in the final NPT walk Date: Fri, 23 Feb 2024 14:09:48 +0100 Message-ID: <20240223130948.237186-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240223130948.237186-1-pbonzini@redhat.com> References: <20240223130948.237186-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1708694087956100001 Content-Type: text/plain; charset="utf-8" The A20 mask is only applied to the final memory access. Nested page tables are always walked with the raw guest-physical address. Unlike the previous patch, in this one the masking must be kept, but it was done too early. Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index 2ddc08b4bb6..8f7011d9663 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -134,7 +134,6 @@ static inline bool ptw_setl(const PTETranslate *in, uin= t32_t old, uint32_t set) static bool mmu_translate(CPUX86State *env, const TranslateParams *in, TranslateResult *out, TranslateFault *err) { - const int32_t a20_mask =3D x86_get_a20_mask(env); const target_ulong addr =3D in->addr; const int pg_mode =3D in->pg_mode; const bool is_user =3D is_mmu_index_user(in->mmu_idx); @@ -417,10 +416,13 @@ do_check_protect_pse36: } } =20 - /* align to page_size */ - paddr =3D (pte & a20_mask & PG_ADDRESS_MASK & ~(page_size - 1)) - | (addr & (page_size - 1)); + /* merge offset within page */ + paddr =3D (pte & PG_ADDRESS_MASK & ~(page_size - 1)) | (addr & (page_s= ize - 1)); =20 + /* + * Note that NPT is walked (for both paging structures and final guest + * addresses) using the address with the A20 bit set. + */ if (in->ptw_idx =3D=3D MMU_NESTED_IDX) { CPUTLBEntryFull *full; int flags, nested_page_size; @@ -459,7 +461,7 @@ do_check_protect_pse36: } } =20 - out->paddr =3D paddr; + out->paddr =3D paddr & x86_get_a20_mask(env); out->prot =3D prot; out->page_size =3D page_size; return true; --=20 2.43.0