Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1702527pxy; Sat, 1 May 2021 23:34:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJYacnQGJgMGIT9pT7mesgWolE6GQh5+P5GU9LDE23XOATjI0k3111lqseBDKn0PcGuN1N X-Received: by 2002:a50:fc0b:: with SMTP id i11mr14663273edr.259.1619937275938; Sat, 01 May 2021 23:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619937275; cv=none; d=google.com; s=arc-20160816; b=WrY78P3Z9z399pVv/8ZN22XATwjUnf21CHI371vB4IZ02k3SYvMJ8r8UNZ/5JZc/8p +9D9hLSQOJimahXUVdTcZWgEHFacjBdwRc+Y3hCeLwKuizCfwCmNsud38mTEahayQsHc UjhMgefigcKYkTHpfyE46EzRYMovla90uPXtFXvCpcn7PcwtJ09NZb0wSGbBo3oNT8TN kBIZsRNXCH5we7b6+2kGa/kXU+1o+w0ugtbNhidSL1NvXutAeSzRqEwGUC4ziDH++UNV vIlEscAgYJ3SHJArDfY88nhVjfqJVe2RR5XgETIf0/3lc6ECvl17eF8peegyc7dEu9MM LCRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XjzGqcCbPjvR88zDOoxG0savu1rMVCF7cd0p0dY/oVE=; b=tof7q5dBPcb9CH3UnL3ga3G2Eoa1FwHFjmPoAzAM6Nq4pvBjEeOer5se4I+UOoe5yA W6NPW5eA13bSdkV33LzdTv96a8+UXlqzS+scA/jQ1E01PJrDW7MwGPW94QZaT8kktfnD c5Kb6rT7BWXReLNR6gGMx6RHWwkWzrXDv6By3iZCDZWRLb/jGFMgnPOvqacEDNJCLAgY wWXYAFnY/J8UOXCu2vL4K7fc0XOfpXM8oJWR7yggOtvH9Ck6pQglBHdBrCE2LFJ1Y9yn d0uf/KPY1xJxVHx6jiy0irM1xanzb1hTyrw8jq1qBfmgnRpAWM5kxpPW3BeFqeZd7GUP wqZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SOUpNoyd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si7384235eje.466.2021.05.01.23.33.54; Sat, 01 May 2021 23:34:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SOUpNoyd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbhEBGcZ (ORCPT + 99 others); Sun, 2 May 2021 02:32:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:59418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhEBGcY (ORCPT ); Sun, 2 May 2021 02:32:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 622FB6134F; Sun, 2 May 2021 06:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619937093; bh=SUTF4qHvvsvOCxRaO7XMs9cQTJeY156G3PPBU4Gks2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SOUpNoydb/Dr01KO8+naCCL9W/VNTnBaeUOGgAEKVeY9Ki8wwSN/8gQXKYt4Eejj9 5ODj0fMX/fFoQnrlDWf0DIuyNGXeU1B5VzF9LMwxHZvEJ1+jVEHYmegGhZQdSqqiQT 2ElXY9X/fhAd0ms8gpUWE1EGsl7CF7uNmtg6MVqQFqTTLjG3BmSYNwDRoUlOQRKwsM /iHufKPwlGmiUSK1jvdTa0yM/xMbUgA6M1PZCE9EDYujnE/iBkj6SsVbqbz8pbkeSe +rB0HbrVWvKcCyAEeRj+m4of7Ad3w2qUphuxf/+YhkT5sygsX45ePs3e9C7cDv9Zn3 HCmDkz5w5Tw2A== Date: Sun, 2 May 2021 09:31:21 +0300 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, Andrew Morton , "Michael S. Tsirkin" , Jason Wang , Alexey Dobriyan , "Matthew Wilcox (Oracle)" , Oscar Salvador , Michal Hocko , Roman Gushchin , Alex Shi , Steven Price , Mike Kravetz , Aili Yao , Jiri Bohac , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Naoya Horiguchi , linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v1 2/7] fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM Message-ID: References: <20210429122519.15183-1-david@redhat.com> <20210429122519.15183-3-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429122519.15183-3-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 29, 2021 at 02:25:14PM +0200, David Hildenbrand wrote: > Let's resturcture the code, using switch-case, and checking pfn_is_ram() > only when we are dealing with KCORE_RAM. > > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport > --- > fs/proc/kcore.c | 35 +++++++++++++++++++++++++++-------- > 1 file changed, 27 insertions(+), 8 deletions(-) > > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c > index 09f77d3c6e15..ed6fbb3bd50c 100644 > --- a/fs/proc/kcore.c > +++ b/fs/proc/kcore.c > @@ -483,25 +483,36 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) > goto out; > } > m = NULL; /* skip the list anchor */ > - } else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { > - if (clear_user(buffer, tsz)) { > - ret = -EFAULT; > - goto out; > - } > - } else if (m->type == KCORE_VMALLOC) { > + goto skip; > + } > + > + switch (m->type) { > + case KCORE_VMALLOC: > vread(buf, (char *)start, tsz); > /* we have to zero-fill user buffer even if no read */ > if (copy_to_user(buffer, buf, tsz)) { > ret = -EFAULT; > goto out; > } > - } else if (m->type == KCORE_USER) { > + break; > + case KCORE_USER: > /* User page is handled prior to normal kernel page: */ > if (copy_to_user(buffer, (char *)start, tsz)) { > ret = -EFAULT; > goto out; > } > - } else { > + break; > + case KCORE_RAM: > + if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { > + if (clear_user(buffer, tsz)) { > + ret = -EFAULT; > + goto out; > + } > + break; > + } > + fallthrough; > + case KCORE_VMEMMAP: > + case KCORE_TEXT: > if (kern_addr_valid(start)) { > /* > * Using bounce buffer to bypass the > @@ -525,7 +536,15 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) > goto out; > } > } > + break; > + default: > + pr_warn_once("Unhandled KCORE type: %d\n", m->type); > + if (clear_user(buffer, tsz)) { > + ret = -EFAULT; > + goto out; > + } > } > +skip: > buflen -= tsz; > *fpos += tsz; > buffer += tsz; > -- > 2.30.2 > -- Sincerely yours, Mike.