Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2042519pxk; Mon, 14 Sep 2020 03:17:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzEDWZOSA0sCavCwqoa+sf0N/AZLIea6lGvs4HZlCKDhXeazn8ezB1ZZ7jMYJRKjmbU0Bp X-Received: by 2002:a17:907:4035:: with SMTP id nk5mr13631744ejb.418.1600078650784; Mon, 14 Sep 2020 03:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600078650; cv=none; d=google.com; s=arc-20160816; b=zb2U5tClmQr98BUp4x5NHTGnTg8AdXWQ+05P35OJPyheNqSuoVtpB+72TXnvhYko/2 2SISaA6ASFOm0bRaYuv6IyYg9ACDTMqyi5YOZ2TnhQ12gR2By8OA8iGtRungCx6zGPih fTzvAq6y/Mb6nuHeFVI8EwhDHVF72Fzrp5Zc65Nb2wjCuouMfOdeCK8lBaPCLD21UguI yV+HIqNgcZA1WfQMRPaCVosLipCvuhENor1j4nNUvqExjdACcRwjEu4wXbhT4yZwfkFZ ORSsbNdYjwCGUZBYQOZXHlj8Ko1CcsfDHJarU4w6ci5cA4th3V09K4GSWBLAYc0KRnl5 hdyg== 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=g+VP2bR/Rz4DnoDsDWRalqlbZavyutbE67Q+yf/G5bk=; b=ccuHPYoiIpHf6cAt/se7Gs4xf9jVEWRApMVzXqT303rFJrS9J4WprrazRSx2bJ6lZn 9PL9VhHrra7ylMsaruJtwD0a+bjkX8LgxpbIpQpkbz0jC9k3wIHkAH34DDG/gY/WefCo c9Ix4MrKIBkt2SZNSdRLYkiZb9rXS7iB5mQ3P3mpFWhXgW2JWf4RkT/goWEk4Xblqe86 FZLMgnN1a72HlLTdt5SaoDjiR3FRpgppLu63xnSAmLHDR3WuM+TwglmUGTV37AWjMIkG 57h0myByQENhRofV+J32WPtmSWaAtttQME3POj9N17s6ZZtdKMIbShwijTcAeyg9Y8Zo aEQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si7077354ejf.457.2020.09.14.03.17.09; Mon, 14 Sep 2020 03:17:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbgINKQT (ORCPT + 99 others); Mon, 14 Sep 2020 06:16:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:44724 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbgINKQG (ORCPT ); Mon, 14 Sep 2020 06:16:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DB162B265; Mon, 14 Sep 2020 10:16:19 +0000 (UTC) From: Oscar Salvador To: akpm@linux-foundation.org Cc: naoya.horiguchi@nec.com, mhocko@kernel.org, tony.luck@intel.com, cai@lca.pw, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador , Oscar Salvador , Stephen Rothwell Subject: [PATCH v3 2/5] mm,hwpoison: refactor madvise_inject_error Date: Mon, 14 Sep 2020 12:15:56 +0200 Message-Id: <20200914101559.17103-3-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200914101559.17103-1-osalvador@suse.de> References: <20200914101559.17103-1-osalvador@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make a proper if-else condition for {hard,soft}-offline. [akpm: remove zone variable and refactor comment] Link: https://lkml.kernel.org/r/20200908075626.11976-3-osalvador@suse.de Signed-off-by: Oscar Salvador Cc: Michal Hocko Cc: Naoya Horiguchi Cc: Qian Cai Cc: Tony Luck Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- mm/madvise.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index a8f18420efeb..4ce66bab53dd 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -872,8 +872,6 @@ static long madvise_remove(struct vm_area_struct *vma, static int madvise_inject_error(int behavior, unsigned long start, unsigned long end) { - struct page *page; - struct zone *zone; unsigned long size; if (!capable(CAP_SYS_ADMIN)) @@ -882,6 +880,7 @@ static int madvise_inject_error(int behavior, for (; start < end; start += size) { unsigned long pfn; + struct page *page; int ret; ret = get_user_pages_fast(start, 1, 0, &page); @@ -898,25 +897,22 @@ static int madvise_inject_error(int behavior, if (behavior == MADV_SOFT_OFFLINE) { pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", - pfn, start); - + pfn, start); ret = soft_offline_page(pfn, MF_COUNT_INCREASED); - if (ret) - return ret; - continue; + } else { + pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", + pfn, start); + /* + * Drop the page reference taken by + * get_user_pages_fast(). In the absence of + * MF_COUNT_INCREASED the memory_failure() routine is + * responsible for pinning the page to prevent it + * from being released back to the page allocator. + */ + put_page(page); + ret = memory_failure(pfn, 0); } - pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", - pfn, start); - - /* - * Drop the page reference taken by get_user_pages_fast(). In - * the absence of MF_COUNT_INCREASED the memory_failure() - * routine is responsible for pinning the page to prevent it - * from being released back to the page allocator. - */ - put_page(page); - ret = memory_failure(pfn, 0); if (ret) return ret; } -- 2.26.2