Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1140284ybg; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6TRxdWbzrVM3rO87/1Q/SVyzHYl+hKAWTRt0XOgoxtPi2w/ry10TIQVqDCt8yTxuDfuFE X-Received: by 2002:a17:906:8286:: with SMTP id h6mr10491993ejx.258.1571427685677; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571427685; cv=none; d=google.com; s=arc-20160816; b=BfDNlkJo2AkCa3K6c3KZVV957QkFQLdgrPCvgD58/+VfpQF2J3FaRqPOZAigfY1KSB SxBSLQfvp8GvX5KdlZQ3UTyYviWS9eG6PbRFOM5Sx6EBlf5AAgPYa02xwq2/u/2CGwyr 7Rb2Th64UrEWM+k3VW+R1rzaIiWN8180QtdgZGGz2T6nm4o8UfuV1OQI/YNatnxNzft/ HrTHv5aMr95eHkfU6IREQRN3NpBhgL0Zh3+ooalEX9b/DwPxPkg/sDpA/X0Akwb9EpfT KbSC3v84K6rMm7y3nohe2z9zPso82SrVwkQnEjmuFarxdThCpKbW/E3+iEj3c/z8w+ip pyLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=VHZABGh8nws8h51i3KjuedzQfcU2MVe0pikXJWnW5yg=; b=s9mMp6E6MgMqGhE5oa6P/uSrcwCGtdIc+k+7muksGXq4rZw7eyWa8KoLb0DrVLqbFm G9vjaAHoLAvvd4ZCf9f6tyOCOr7tm93LRvkEJwcfH9ciqG3p5txvI9Va/VpIiezUNJ1t 0Qzf9v+MoVGXpkJH9YgrPOQS7jp1PybeVWTYdUfTPK/GYv1s5LKnPgBoRSpivVWu6kDC LFaPvGmXHyHufF/nLxyvrYPdDr+10Ga2gR/T6qPrjWun6mD+N5t9wgu6901jbS4Qxtl1 Kd3eV3X5bo/H46kkt2ya+/jO/9lYlOblPR9E/Zf152ptDfym6vyZntdiFifTbx2cozAU H/DA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si4811304edc.231.2019.10.18.12.40.20; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440207AbfJQOVs (ORCPT + 99 others); Thu, 17 Oct 2019 10:21:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:40782 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440153AbfJQOVj (ORCPT ); Thu, 17 Oct 2019 10:21:39 -0400 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); -- 2.12.3