Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1186563rdb; Fri, 1 Dec 2023 09:05:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFLGNdH7ZrbXcjIVIWsG+sFRdPpUI8CZ1z/okOYuGIhQCddfgwFPjyUiTsnrvL6+VxFgbo X-Received: by 2002:a17:902:ba93:b0:1d0:3f8:b63b with SMTP id k19-20020a170902ba9300b001d003f8b63bmr10951517pls.21.1701450335194; Fri, 01 Dec 2023 09:05:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701450335; cv=none; d=google.com; s=arc-20160816; b=Uif7w7I5eE7yvgig2WyK7fvXPcMaGOWgXwCoEriga/4nEEw85sZSlaxIKdTSDvH8zG EhCpJGeJmvvNndk9mruJ9tqG5n3nM/vcq9Q4YTBws/EleU2RDGK6LnkOMb2nJLcJP9RA MUOZM7Eovyow78mOSKww2NAPSGIJKMd+ZMbn766X3oUmPYnxzG6yOthcpRFN4qLY7Mef bEnKeXjeHAsnKX1mN21sbRb6S8PDTpD5REOyiTYMx+nPq9csJvjaXatQk95kRG5A+Yal cL5wWhtb3uXRz5pX7tSP3WjQJ8uPthxsn4ntebJT6DHvSmnPcnn414u826Qq2UXuwH/9 LJpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=YbmCSI5K+Qp+wla/FUZNboDkH6vkaCc9VLdnolKakNc=; fh=LqtWlYCc6L5qota6KkOvGmZB/VbPW4l2P0g+sR7CYV8=; b=vPUwqE7XKN8ae/MVJ/hVGHOinaVeYEibBwEctputCoYpgxcoUXeexTLcjJWQE1kXOv BsVQzWyjvCla76yuyfdglK9tPh28RNineO11GzolPnMyunc/ArlORdMqm5nEwczONZ9p uVqwbUizhcmWswFa95mLqFJ1gHbK5A3ccXHaa/lnyF7cKju+xnni89kX4Sb2KYV07C1f LpOBDEBW5va5FDZfbV31NHiABsrErsAzjn2dl+X1LcfTOtsffxLb/2xUETMZsL64AThr yO1/xDGucLnKyLHaAzIYxtAntrIKF3mX8KBVJuIBcwo9embR0zOM4N60jCyB8NzkvzmI XgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=noFyjEJv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h2-20020a170902704200b001d0519835d9si1724940plt.112.2023.12.01.09.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 09:05:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=noFyjEJv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D4C6D835B80B; Fri, 1 Dec 2023 09:05:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378583AbjLAREs (ORCPT + 99 others); Fri, 1 Dec 2023 12:04:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjLAREr (ORCPT ); Fri, 1 Dec 2023 12:04:47 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FD87F3 for ; Fri, 1 Dec 2023 09:04:53 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db4004a8aa9so948033276.1 for ; Fri, 01 Dec 2023 09:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701450292; x=1702055092; 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=YbmCSI5K+Qp+wla/FUZNboDkH6vkaCc9VLdnolKakNc=; b=noFyjEJvzmVlRRLojlSuZXrCrc4Yzgu+xDbrsD/cVPN7F03GE6eMPPp2H+YzBE1dwq R+pO5gCtR8CSLpl9WZGog5pt0o+51OULhEANXl1ORn/9U3Ib3uS4kVhhHjjw+QRjnlQb iTobRKJhTmdnsnzXNvxcmnEVfBYI6g+xvpIe+Tn2XX1MxywHY4ZVtrqQmbs1EYx5S3XX 25t/M24RG29rgjcLg+dXhKtukBHzNIg4uz4B7MlaSLZ9EvMhB+pajfNMychzXyjUsg3/ fjgGd5Uu1js1Yj+iyPEA6TCAsGuHPdGgKVVNnpCKBgBMYuBiIll9KqM5lW05R0huS1IL COgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701450292; x=1702055092; 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=YbmCSI5K+Qp+wla/FUZNboDkH6vkaCc9VLdnolKakNc=; b=X/hpqVooAGpLMs6Ugtm1/jVolKmHA7osmA1uFdNFfcOp/X4oXk9qx5reAFTTRkk+lQ 3FMx06YJozA+gY73y+HbMvoAHF8xp5VIL/EQ4jTMGBodhmvb2wNYeL/EoRASp6zX/U1w omIox5b03v1jyPgO1h89HQx52jDHGYF79YVa5hi/HPZDi1oHqhDSKX4ksYdeXgZNR4Pp d38FByQ56VnbNMsw1X+uMbNqN1rli3Ref18/Hr6Z0z5RC012Z7GFEPsyxhLAUzCICSYW 19myXs+Fq3UfGfU+EwYIwxr4XSJa9nPTcNUmS5KrG6u1GgMkKmcIHXtw6i2BdN8OgktP KRdg== X-Gm-Message-State: AOJu0YyxciAiHQYLpwqb4ED763tzqr1EOzzhDZF1wpNWgo+Eslv8p5kU +DnA/AFF+DgEaZJhDAEBYWtltNLsNXY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:6e83:0:b0:d9a:e3d9:99bd with SMTP id j125-20020a256e83000000b00d9ae3d999bdmr780648ybc.5.1701450292702; Fri, 01 Dec 2023 09:04:52 -0800 (PST) Date: Fri, 1 Dec 2023 09:04:51 -0800 In-Reply-To: <20231123003513.24292-3-ankita@nvidia.com> Mime-Version: 1.0 References: <20231123003513.24292-1-ankita@nvidia.com> <20231123003513.24292-3-ankita@nvidia.com> Message-ID: Subject: Re: [PATCH v2 2/4] mm: Add poison error check in fixup_user_fault() for mapped pfn From: Sean Christopherson To: ankita@nvidia.com Cc: jgg@nvidia.com, alex.williamson@redhat.com, naoya.horiguchi@nec.com, akpm@linux-foundation.org, tony.luck@intel.com, bp@alien8.de, linmiaohe@huawei.com, rafael@kernel.org, lenb@kernel.org, james.morse@arm.com, shiju.jose@huawei.com, bhelgaas@google.com, pabeni@redhat.com, yishaih@nvidia.com, shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com, aniketa@nvidia.com, cjia@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, vsethi@nvidia.com, acurrid@nvidia.com, apopple@nvidia.com, anuaggarwal@nvidia.com, jhubbard@nvidia.com, danw@nvidia.com, mochs@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-edac@vger.kernel.org, linux-acpi@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 01 Dec 2023 09:05:03 -0800 (PST) On Thu, Nov 23, 2023, ankita@nvidia.com wrote: > From: Ankit Agrawal > > The fixup_user_fault() currently does not expect a VM_FAULT_HWPOISON > and hence does not check for it while calling vm_fault_to_errno(). Since > we now have a new code path which can trigger such case, change > fixup_user_fault to look for VM_FAULT_HWPOISON. > > Also make hva_to_pfn_remapped check for -EHWPOISON and communicate the > poison fault up to the user_mem_abort(). I would much prefer the KVM change be split out to its own patch, I see no reason why it needs to be bundled with the fixup_user_fault() change. KVM will set pfn to KVM_PFN_ERR_FAULT before and after the fixup_user_fault() change. > Signed-off-by: Ankit Agrawal > --- > mm/gup.c | 2 +- > virt/kvm/kvm_main.c | 6 ++++++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 231711efa390..b78af20a0f52 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1414,7 +1414,7 @@ int fixup_user_fault(struct mm_struct *mm, > } > > if (ret & VM_FAULT_ERROR) { > - int err = vm_fault_to_errno(ret, 0); > + int err = vm_fault_to_errno(ret, FOLL_HWPOISON); > > if (err) > return err; > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 486800a7024b..2ff067f21a7c 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2731,6 +2731,12 @@ kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool interruptible, > r = hva_to_pfn_remapped(vma, addr, write_fault, writable, &pfn); > if (r == -EAGAIN) > goto retry; > + > + if (r == -EHWPOISON) { > + pfn = KVM_PFN_ERR_HWPOISON; > + goto exit; > + } > + > if (r < 0) > pfn = KVM_PFN_ERR_FAULT; I vote for if (r == -EHWPOISON) pfn = KVM_PFN_ERR_HWPOISON; else if (r < 0) pfn = KVM_PFN_ERR_FAULT; or even opportunstically fix the < 0 weirdness: if (r == -EHWPOISON) pfn = KVM_PFN_ERR_HWPOISON; else if (r) pfn = KVM_PFN_ERR_FAULT; It's rather confusing to see a goto in one error path but an effective fallthrough in a different error path, i.e. gives the impression that KVM_PFN_ERR_HWPOISON has some special behavior that doesn't apply to KVM_PFN_ERR_FAULT.