Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp241376pxk; Thu, 17 Sep 2020 01:32:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvyjZrGsihhCyIRdiI6xZkumGKm2SoxxI+FNdNJkh972IJPuoQZCkT9CnHEfEWwdNU7Ftn X-Received: by 2002:aa7:dd4b:: with SMTP id o11mr31048869edw.251.1600331569177; Thu, 17 Sep 2020 01:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600331569; cv=none; d=google.com; s=arc-20160816; b=tb9ogHW4G5A20MomvETF5sCBgnjJE6lK4OjPATp1+JqgnexCi2RaUPPl1DvYpJerB4 hEBjdwgcAOhk4nr2yJNVfVfVoOum0a8SToVk/1E8a1DnUV3+sPYFMF1At1HVLXii+tdR wOlqS8EV6vpgdaD3BS0xp+CUKOWI/yM1+jQHHnX76jDA2QLaUYcHHSjShVgCmnaeejcw mA0FW2ub26+qGiW6eAz02m3Zmeq0TEY7RLOLtAeVWR3C81F9FyCDOSDvghKXP3AISY3/ xXzO7PMxjy2MRs+vzqodE+1bGj14P0+8z7Km39dR7CAmeZBMXGUjVGrTZWLzGVzNlhHn 8Hyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=0LXR+XSwiDNP/W/BYFv3GlJPIL8ZZMgZKe6bSxuV9ZA=; b=eFZ8JUZxjLGttJIVyWcRDAA6I5ezZc0vl1vOmxj7yxhMnZ+Sk0aWJPbR+S1n11qRd6 mMuV8o/Q9uUA30sGBDjyOTKUbJCTskt+CWK+SetyS59VMH+WMSkBHUpkW+sNSNmeYgYN ILeWurGNCFJe5dqMj5dax9sEMQMoKibROkycjAKUOp+UeYXRkKk8C8DU/aaBjyKsf9sD vRbg3uFOIfC+V0X0A5VD7QJ14sJdOiNtxPNxzO3MtsbmkamcyUqbgCIDB7ykCvvAj8o/ S9kq6PlQepT3YLbyVQjBD0B71YdkMUl6eBHlHSyfGwqTFBX2Ue5N6iakF/GG+RS1odCT cP1A== 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 j22si10059159eds.357.2020.09.17.01.32.25; Thu, 17 Sep 2020 01:32:49 -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 S1726539AbgIQI3u (ORCPT + 99 others); Thu, 17 Sep 2020 04:29:50 -0400 Received: from mx2.suse.de ([195.135.220.15]:56742 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgIQI2m (ORCPT ); Thu, 17 Sep 2020 04:28:42 -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 A0572B053; Thu, 17 Sep 2020 08:29:05 +0000 (UTC) From: Oscar Salvador To: akpm@linux-foundation.org Cc: aris@ruivo.org, 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 Subject: [PATCH v4 4/7] mm,hwpoison: refactor madvise_inject_error Date: Thu, 17 Sep 2020 10:10:46 +0200 Message-Id: <20200917081049.27428-5-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200917081049.27428-1-osalvador@suse.de> References: <20200917081049.27428-1-osalvador@suse.de> 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] Signed-off-by: Oscar Salvador --- mm/madvise.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 4d87b31a1576..4a48f7215195 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -869,8 +869,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)) @@ -879,6 +877,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); @@ -895,25 +894,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