From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D456CC71135 for ; Fri, 13 Jun 2025 22:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=s2QLz2fm2P0Zm24k+moWxAGfgzrhlJlOIYP2dcn2WQo=; b=bZaDm3PnzvmWta9568HPCjSI3+ uDDmkbNNSgQEde5qJk+ItrOzXWnYI5sitFv7FFD/H7ywwvTZBehUNf+KeRoCmkNQTbRTArpvuGYtg XldCUthvk6FlSbYmrqKPQj7DxP8+FTaIuJW8yYA1kJxbJXw6HOImMwOWYqsWfYnZure+PH75hDExk 5MWSyVWnFDWsqHQdNuVIU+r6cdtAHAqhLicRYVEO+tVVhog1q65wER3OkNwyNb6LG3G3DJEEqHg6Q +R/jw4A7s6eZK8IL9JEcMtuJwTl0UKOSXUoYz3X1Bq0uyqXnATYzNkZKDI6uVeKAGk2oIYZ+ftBph IiKHmaHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCto-00000000E8R-1dR4; Fri, 13 Jun 2025 22:29:24 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCtm-00000000E7l-05Oh for kvm-riscv@lists.infradead.org; Fri, 13 Jun 2025 22:29:23 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-313d6d671ffso1515545a91.2 for ; Fri, 13 Jun 2025 15:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749853760; x=1750458560; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=Qcryn+P0jOOemVLGMmX/IXmB/PAJlvHgd0oTFRO82mNDdlgw1WFLBnPt80BBptC+Zj yVTg8Rb6AZeg9zNzybB3qjLNVcG92ryyehS36FSyNOxjLySL9tm7fGgpxDD3UXR947Kv EYv6BPqYew1jjM6qgPLVqRvzsdNOHr8jDQalYYpNEKKdMBoIzv8/ZwHilxbJ5+pJs1N+ 2VTptHIlRHSkyWNemVMMgBSZJCey8KJWuJSMA+TTdtjBkYOvVgW5qzp57hlpz2DCashg zyrk05E90bqlaQdCggFLMKaV0r7pHOJPJ/atfJkLfb8oQqWvwDnULJIrDFQCR23qAnAv +SJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749853760; x=1750458560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=UEXTbhlM/VzoTPjLgK6dhP1l/7T/JDS8rzGWzxtPPHMUJ7Mzq07Tncwx3fd7qtUftN FFtMn1ifEYOb5qMZo1A4uhhGQgN9v19AmerS1ETEENfbqXlRNMXnGen5VlJLpmcqXUea POtEwqyMqlYBdjOUuX1ToqTqU5OVm+SiwVxoxDD8vsfOD98c183vx5maJ7w43DsMegj2 yaMAW8iwx8FRpKm0UziAvtv7q9C+D9XTTfC9pM0rGixTndTrdX6KOZppKabQeThZEPQ0 WbvErz8+L9sSBQfsvVQhsYzHw/ZTrlPzlk5tdzxqN2MFo8mIKo7rw3hRC7M/SeGI6N7Y 5V+Q== X-Forwarded-Encrypted: i=1; AJvYcCXRBsT9pLaqIx5WGsQc4Z+o2AjhYOFRNgNZyZnlnFHHp7XAQZ3CkQS8yV7/RCOkt/SaaHC1xvHQmRE=@lists.infradead.org X-Gm-Message-State: AOJu0YzNf4RIgYHRuLBmPLJVN6CE1jQZnqqmDEy2mrLBPiF5t3/B/8Lb 0b4bj1B3YTq1UCD3+OsCukYL0RpWiRTxMFvmafcXqrMoutZXN6U4pYzXcd6dchh5Y26w/i2F9dz jZdGxZA== X-Google-Smtp-Source: AGHT+IGywTlpl0dHWnufpJSJlj4XpNlHL6UkXqc9RZbcriTQyKRR+zlmrTb17NJPljis76xDw4xc0g5PFgU= X-Received: from pjbsr4.prod.google.com ([2002:a17:90b:4e84:b0:313:2ad9:17ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2dd2:b0:312:f88d:25f9 with SMTP id 98e67ed59e1d1-313f1c7dacfmr2043479a91.7.1749853760694; Fri, 13 Jun 2025 15:29:20 -0700 (PDT) Date: Fri, 13 Jun 2025 15:29:19 -0700 In-Reply-To: <20250612-70c2e573983d05c4fbc41102@orel> Mime-Version: 1.0 References: <50989f0a02790f9d7dc804c2ade6387c4e7fbdbc.1749634392.git.zhouquan@iscas.ac.cn> <20250611-352bef23df9a4ec55fe5cb68@orel> <20250612-70c2e573983d05c4fbc41102@orel> Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Avoid re-acquiring memslot in kvm_riscv_gstage_map() From: Sean Christopherson To: Andrew Jones Cc: zhouquan@iscas.ac.cn, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250613_152922_078240_289AF3F3 X-CRM114-Status: GOOD ( 12.03 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org On Thu, Jun 12, 2025, Andrew Jones wrote: > On Wed, Jun 11, 2025 at 09:17:36AM -0700, Sean Christopherson wrote: > > Looks like y'all also have a bug where an -EEXIST will be returned to userspace, > > and will generate what's probably a spurious kvm_err() message. > > On 32-bit riscv, due to losing the upper bits of the physical address? Or > is there yet another thing to fix? Another bug, I think. gstage_set_pte() returns -EEXIST if a PTE exists, and I _assume_ that's supposed to be benign? But this code returns it blindly: if (writable) { mark_page_dirty(kvm, gfn); ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, false, true); } else { ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, true, true); } if (ret) kvm_err("Failed to map in G-stage\n"); out_unlock: kvm_release_faultin_page(kvm, page, ret && ret != -EEXIST, writable); spin_unlock(&kvm->mmu_lock); return ret; and gstage_page_fault() forwards negative return codes: ret = kvm_riscv_gstage_map(vcpu, memslot, fault_addr, hva, (trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false); if (ret < 0) return ret; and so eventually -EEXIST will propagate to userspace. I haven't looked too closely at the RISC-V MMU, but I would be surprised if encountering what ends up being a spurious fault is completely impossible. > The diff looks good to me, should I test and post it for you? If you test it, I'll happily write changelogs and post patches. -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 505A9153BE8 for ; Fri, 13 Jun 2025 22:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749853762; cv=none; b=AwMZ8FxvyDFLIk24ToGhZ3yv/jpfVXBGVLBcgpbbrUI7jhh8XO5n9K5JSWwtUtRiWuEH2jph1oibCIIQuUt+0zWDMo29Prmm9NzuwmB4m5dSNHCgmyKfgP9p1Ca9BjvQ15s644n04mJWsLFfFxK7q9Ok/pTbD9OZfQAScXPffZE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749853762; c=relaxed/simple; bh=7dCRP5RC5vW665I3kmTd5GcphWE+dNmrueqC0walbck=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jVWu5L2Zz6RwmA6edzkO336wPpsfJxnza0pX9fKV1e/4FBa/tri0+orz9l7qol5yGTRMfQ33wgzS6QyM0ANP4tCEUjV4nKLfw8Iah6n0AMf6z9Y0bVZcwzulyQj3Ed/t6pXFWxa/UvBYjxnPqv4i0G5TxbJn2LARi8qqlK1LHJc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CrR0hz8m; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CrR0hz8m" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30a59538b17so2471184a91.3 for ; Fri, 13 Jun 2025 15:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749853760; x=1750458560; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=CrR0hz8mdmzWNoevcFIiL0BXOwYdobJn9kLJUVj8ID21WkH/byxo6YSFDncLoZZLJu 5qVAAJHARoCaSw0mq89Iz+5NcYVH9S2TSA0/8bh9+tfA5oxctk4H1VIZqZZgwT71jDVF rNnyly+WCB5Yt2/NxxEhNe4PoZpCIRFiP2MgNFuRrySP9c7i3mwAVxEZi/8154/cNSab AHwVpOcUCBab3RbytavDuO3r3z2pGtrj/6oK6JYzRsv6CAqwZYqjodCJK+J6QliJCKY1 UhzFH3mcL4t9H/jY0IN7OgrFb3ziY0Bj940ZDLWu/jR2SDqNsObzs1n4xPMz3fPW+Mw+ 7Tug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749853760; x=1750458560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=da6vhPwHTBXmAPiZlhZ88O+bRqR27hQW76PJmL1lVo4uN1EpO6xmJ7Pse6N9mtnygT rN+QDYWjRHmreu4PR4FFNCFMooD7gtygYrP0ghCZ58IeBiU4g9iNBjPLbGfH5dCpJyBl 6IrTsv5DGRmQOtvRLy1xJG/1rIi8kTalsgLj05QzzcwTSDFB0GhVqfhnaNrTYHW+7X4X 1sWWXw1kk/Z8TjDwV2C7xlkd+qGOhLBjbnIF0IMBP0op0R15DUyRiff7Y44/EX+LW3PJ J6Ra1Uesm3IzQuBa8fdm4y3f0N0IVft1a7IzLk8eetGo1iSjrm8K9bIW7rE8/k7jGrIT 6RlQ== X-Forwarded-Encrypted: i=1; AJvYcCU76El40XRjtcCI3mwLHGda8gxcPbTCBd9JnlNuZMIGQ9XLyyiTuH+EvbIE0PA7HbF3c34=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7r68bdAcw52Yx7Of+XSER0xNYcvRe9bSWPiBExJPeswyWiKkd JDXWyKqF5VDEuQPpRnNRxOJpNUIpqAIKwM6hPyX+he48hATm4Ib1KyEXgHFkaEru+xTJbItByZC bxSlTJg== X-Google-Smtp-Source: AGHT+IGywTlpl0dHWnufpJSJlj4XpNlHL6UkXqc9RZbcriTQyKRR+zlmrTb17NJPljis76xDw4xc0g5PFgU= X-Received: from pjbsr4.prod.google.com ([2002:a17:90b:4e84:b0:313:2ad9:17ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2dd2:b0:312:f88d:25f9 with SMTP id 98e67ed59e1d1-313f1c7dacfmr2043479a91.7.1749853760694; Fri, 13 Jun 2025 15:29:20 -0700 (PDT) Date: Fri, 13 Jun 2025 15:29:19 -0700 In-Reply-To: <20250612-70c2e573983d05c4fbc41102@orel> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <50989f0a02790f9d7dc804c2ade6387c4e7fbdbc.1749634392.git.zhouquan@iscas.ac.cn> <20250611-352bef23df9a4ec55fe5cb68@orel> <20250612-70c2e573983d05c4fbc41102@orel> Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Avoid re-acquiring memslot in kvm_riscv_gstage_map() From: Sean Christopherson To: Andrew Jones Cc: zhouquan@iscas.ac.cn, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Content-Type: text/plain; charset="us-ascii" On Thu, Jun 12, 2025, Andrew Jones wrote: > On Wed, Jun 11, 2025 at 09:17:36AM -0700, Sean Christopherson wrote: > > Looks like y'all also have a bug where an -EEXIST will be returned to userspace, > > and will generate what's probably a spurious kvm_err() message. > > On 32-bit riscv, due to losing the upper bits of the physical address? Or > is there yet another thing to fix? Another bug, I think. gstage_set_pte() returns -EEXIST if a PTE exists, and I _assume_ that's supposed to be benign? But this code returns it blindly: if (writable) { mark_page_dirty(kvm, gfn); ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, false, true); } else { ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, true, true); } if (ret) kvm_err("Failed to map in G-stage\n"); out_unlock: kvm_release_faultin_page(kvm, page, ret && ret != -EEXIST, writable); spin_unlock(&kvm->mmu_lock); return ret; and gstage_page_fault() forwards negative return codes: ret = kvm_riscv_gstage_map(vcpu, memslot, fault_addr, hva, (trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false); if (ret < 0) return ret; and so eventually -EEXIST will propagate to userspace. I haven't looked too closely at the RISC-V MMU, but I would be surprised if encountering what ends up being a spurious fault is completely impossible. > The diff looks good to me, should I test and post it for you? If you test it, I'll happily write changelogs and post patches. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F07FBC71136 for ; Fri, 13 Jun 2025 22:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=9udbEXIZcMjpAZHBAsY7p7z0gaqc2l0MRePZYLkkUtc=; b=4aCsvJecNyMydR6cBzBBXNW8Zw u4iuPiPNKJUYIPa4kxSHibadMlK1SMdFEoT8bqGeUeYY2gzk3x4YMw+/l5VzpPpmGz3s9dt7RGLJz k3pAWWznO/oTp0Px5A92ypxScycY4BAHo+fqlvy2vcAEeS3e+BgXHtXdsPPpO1L5HINQBVNPu2O67 UyEZ0FhFDDI8Lu2cRvqNC2GomypBiLqDGJJ+d6FOuUe2OWmXM2KTo4/Imt3myUKlxK5UzYoxnd4Tk A0nquz/BSbDPCphOeR1howDePO8ZYURSfylyMQjcUskGFdzU/nfrCn1C+jSjVdXawaMsBIGcEdGwY 9/y2ZrFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCto-00000000E8c-2vpf; Fri, 13 Jun 2025 22:29:24 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCtm-00000000E7k-0uJD for linux-riscv@lists.infradead.org; Fri, 13 Jun 2025 22:29:23 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-31366819969so2067236a91.0 for ; Fri, 13 Jun 2025 15:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749853760; x=1750458560; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=Qcryn+P0jOOemVLGMmX/IXmB/PAJlvHgd0oTFRO82mNDdlgw1WFLBnPt80BBptC+Zj yVTg8Rb6AZeg9zNzybB3qjLNVcG92ryyehS36FSyNOxjLySL9tm7fGgpxDD3UXR947Kv EYv6BPqYew1jjM6qgPLVqRvzsdNOHr8jDQalYYpNEKKdMBoIzv8/ZwHilxbJ5+pJs1N+ 2VTptHIlRHSkyWNemVMMgBSZJCey8KJWuJSMA+TTdtjBkYOvVgW5qzp57hlpz2DCashg zyrk05E90bqlaQdCggFLMKaV0r7pHOJPJ/atfJkLfb8oQqWvwDnULJIrDFQCR23qAnAv +SJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749853760; x=1750458560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=ZFPf1Trab3VFRaSdnnErYZBI2wlU6ZWOEk5zZKt0ltdZAEp0IAkdv1YptNlqhH88u+ fc2vpOI2qH0rFsZ9lxC7q7pcTHDslQVCru+ePmkAwMAAp8AiL+Wyh7XkiM/MNSWJzL/A mpUH0KXEs2QKd5Vj9nUZ3Dj9wgrphMXETD8MdZam3s6VdGL5IRuEleBIQpaInt744dCw K0KCNZM+q2p7+Myrdp5MTxmTrCCkSUMdHQBTjU4XGtEj2JN5Oum8pPKNsTbb7FmDj4PN ZcTjMjNqwqR3PFxLUStY6y5ZtlO1TjB6x8r+89Oo0yAF28g+I70e+IcEnrz7LHUKTS8S r8pw== X-Forwarded-Encrypted: i=1; AJvYcCXDObB34Q3D1Nd5u18jMvOIQsbtVJrgp1BAtt8dupdv6dC2Pqjjs7g4jqoggDi1n1WW1rJfiocO19ci7A==@lists.infradead.org X-Gm-Message-State: AOJu0YwpzqG79B39K5wrR7CtsH/MVZx3DHLlxrEFWz/4OhwjTD5Sv0J0 wRIyXM7jJgdYtL+FzwW59FtSyg+It4Avba1EEO5pVQKTtSPWuMlsm1PGtHtR/yujAWsydXN/U02 pjTvc+g== X-Google-Smtp-Source: AGHT+IGywTlpl0dHWnufpJSJlj4XpNlHL6UkXqc9RZbcriTQyKRR+zlmrTb17NJPljis76xDw4xc0g5PFgU= X-Received: from pjbsr4.prod.google.com ([2002:a17:90b:4e84:b0:313:2ad9:17ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2dd2:b0:312:f88d:25f9 with SMTP id 98e67ed59e1d1-313f1c7dacfmr2043479a91.7.1749853760694; Fri, 13 Jun 2025 15:29:20 -0700 (PDT) Date: Fri, 13 Jun 2025 15:29:19 -0700 In-Reply-To: <20250612-70c2e573983d05c4fbc41102@orel> Mime-Version: 1.0 References: <50989f0a02790f9d7dc804c2ade6387c4e7fbdbc.1749634392.git.zhouquan@iscas.ac.cn> <20250611-352bef23df9a4ec55fe5cb68@orel> <20250612-70c2e573983d05c4fbc41102@orel> Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Avoid re-acquiring memslot in kvm_riscv_gstage_map() From: Sean Christopherson To: Andrew Jones Cc: zhouquan@iscas.ac.cn, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250613_152922_247488_64C4E6CD X-CRM114-Status: GOOD ( 12.03 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Jun 12, 2025, Andrew Jones wrote: > On Wed, Jun 11, 2025 at 09:17:36AM -0700, Sean Christopherson wrote: > > Looks like y'all also have a bug where an -EEXIST will be returned to userspace, > > and will generate what's probably a spurious kvm_err() message. > > On 32-bit riscv, due to losing the upper bits of the physical address? Or > is there yet another thing to fix? Another bug, I think. gstage_set_pte() returns -EEXIST if a PTE exists, and I _assume_ that's supposed to be benign? But this code returns it blindly: if (writable) { mark_page_dirty(kvm, gfn); ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, false, true); } else { ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, true, true); } if (ret) kvm_err("Failed to map in G-stage\n"); out_unlock: kvm_release_faultin_page(kvm, page, ret && ret != -EEXIST, writable); spin_unlock(&kvm->mmu_lock); return ret; and gstage_page_fault() forwards negative return codes: ret = kvm_riscv_gstage_map(vcpu, memslot, fault_addr, hva, (trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false); if (ret < 0) return ret; and so eventually -EEXIST will propagate to userspace. I haven't looked too closely at the RISC-V MMU, but I would be surprised if encountering what ends up being a spurious fault is completely impossible. > The diff looks good to me, should I test and post it for you? If you test it, I'll happily write changelogs and post patches. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv