From patchwork Thu Oct 17 14:21:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 11196203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E251513BD for ; Thu, 17 Oct 2019 14:22:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B90EA2089C for ; Thu, 17 Oct 2019 14:22:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B90EA2089C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B73B28E0015; Thu, 17 Oct 2019 10:21:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AAAAB8E001A; Thu, 17 Oct 2019 10:21:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 922A38E0015; Thu, 17 Oct 2019 10:21:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 68CDA8E0019 for ; Thu, 17 Oct 2019 10:21:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 07900181AEF3E for ; Thu, 17 Oct 2019 14:21:40 +0000 (UTC) X-FDA: 76053489960.08.coil25_e77e7806b318 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,osalvador@suse.de,:n-horiguchi@ah.jp.nec.com:mhocko@kernel.org:mike.kravetz@oracle.com::linux-kernel@vger.kernel.org:osalvador@suse.de,RULES_HIT:30054:30070,0,RBL:195.135.220.15:@suse.de:.lbl8.mailshell.net-62.2.6.2 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:suse.de-dnsbl7.mailshell.net-127.0.0.120,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: coil25_e77e7806b318 X-Filterd-Recvd-Size: 2549 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Oct 2019 14:21:39 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2A3DDB488; Thu, 17 Oct 2019 14:21:38 +0000 (UTC) From: Oscar Salvador To: n-horiguchi@ah.jp.nec.com Cc: mhocko@kernel.org, mike.kravetz@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH v2 15/16] mm/hwpoison-inject: Rip off duplicated checks Date: Thu, 17 Oct 2019 16:21:22 +0200 Message-Id: <20191017142123.24245-16-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20191017142123.24245-1-osalvador@suse.de> References: <20191017142123.24245-1-osalvador@suse.de> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: memory_failure() already performs the same checks, so leave it to the main routine. Signed-off-by: Oscar Salvador --- mm/hwpoison-inject.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c index 0c8cdb80fd7d..fdcca3df4283 100644 --- a/mm/hwpoison-inject.c +++ b/mm/hwpoison-inject.c @@ -14,49 +14,22 @@ static struct dentry *hwpoison_dir; static int hwpoison_inject(void *data, u64 val) { unsigned long pfn = val; - struct page *p; - struct page *hpage; - int err; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (!pfn_valid(pfn)) - return -ENXIO; - - p = pfn_to_page(pfn); - hpage = compound_head(p); - - if (!hwpoison_filter_enable) - goto inject; - - shake_page(hpage, 0); - /* - * This implies unable to support non-LRU pages. - */ - if (!PageLRU(hpage) && !PageHuge(p)) - return 0; - - /* - * do a racy check to make sure PG_hwpoison will only be set for - * the targeted owner (or on a free page). - * memory_failure() will redo the check reliably inside page lock. - */ - err = hwpoison_filter(hpage); - if (err) - return 0; - -inject: pr_info("Injecting memory failure at pfn %#lx\n", pfn); return memory_failure(pfn, 0); } static int hwpoison_unpoison(void *data, u64 val) { + unsigned long pfn = val; + if (!capable(CAP_SYS_ADMIN)) return -EPERM; - return unpoison_memory(val); + return unpoison_memory(pfn); } DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");