Received: by 10.223.176.5 with SMTP id f5csp65851wra; Tue, 6 Feb 2018 17:18:30 -0800 (PST) X-Google-Smtp-Source: AH8x227JspBCA6WmxOPe420mrVoCjU1/I72eceO8/++3hTBVaDFShEYOx1E5Ss9/nrMkXte4Kwwa X-Received: by 2002:a17:902:b7c3:: with SMTP id v3-v6mr4228873plz.307.1517966310881; Tue, 06 Feb 2018 17:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517966310; cv=none; d=google.com; s=arc-20160816; b=aqLBuzBqehZeVAqmnSWIPoehqJxk7aRBO3a8ERmdRDI6K54iJ9q8UfqL7GdHHMQKoQ KBtUMCns9Ahb9v1hEHvuTUiCWZZOnFOCNWSUjTZapd6G6HTE6qa9psS+wONtw8lm24Rh uwE3OtqnsJCmQJLOotOZVtxRa4ue6O1DNrWt7n8ESb4tbrbCJMnojHMmMTU70hy8VKKp ZJCHdrLiIjbGNTOD2l4z7VXf6tmthiNZ5glXzzw2qp5iWf1fm1VKKazr5TYm8KUyVX8P amN2FCTOzIrvmpZb5EEsbFBkM8ETDFGTrQ6ElZd81iKd0CTSsDnA/yAUvzM/AN8oJpTc H5Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=PuduDkmSA5+s7v5x0E35lmX3Tlzd7dC/6mKwqnKQ8uU=; b=TxcFgA3GaD5tLMwOv0Qhq0BtrFksljPlZ6SvT8DnD0aFbNmx5IiO5/y9etLKVUkTUZ cKeKP5ENyrK+gvo01je7l4DIFCVvzspc72nmIVE5UjZ3bHnznKY2ur/s9FWpPk4vunfH PTPUmEFnadXZLf1+FXfF/yHA+4Scyp9KrlgTajtCh5++tW0TbLsi/MihMhzXjXt6ygTh SorjpgK5M4rrvCHjqINj3jnpGhJcBFqPgVARZ7APWfZVc4fH29jyIHfrTQV2Kb2Q19De LhT21va/8f2Yp233qH8ZDiLVzXBVQAWWiXAIxAzfXneB7eo0VWEK5cBmFMCH+/JMA87u LPmw== 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 h3si257095pfk.174.2018.02.06.17.18.09; Tue, 06 Feb 2018 17:18:30 -0800 (PST) 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 S1754268AbeBGBQi convert rfc822-to-8bit (ORCPT + 99 others); Tue, 6 Feb 2018 20:16:38 -0500 Received: from tyo161.gate.nec.co.jp ([114.179.232.161]:47284 "EHLO tyo161.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754189AbeBGBQh (ORCPT ); Tue, 6 Feb 2018 20:16:37 -0500 Received: from mailgate01.nec.co.jp ([114.179.233.122]) by tyo161.gate.nec.co.jp (8.15.1/8.15.1) with ESMTPS id w171GJqp018874 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 7 Feb 2018 10:16:19 +0900 Received: from mailsv02.nec.co.jp (mailgate-v.nec.co.jp [10.204.236.94]) by mailgate01.nec.co.jp (8.15.1/8.15.1) with ESMTP id w171GJHm011061; Wed, 7 Feb 2018 10:16:19 +0900 Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv02.nec.co.jp (8.15.1/8.15.1) with ESMTP id w171Ej6J004038; Wed, 7 Feb 2018 10:16:19 +0900 Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.152] [10.38.151.152]) by mail01b.kamome.nec.co.jp with ESMTP id BT-MMP-678765; Wed, 7 Feb 2018 10:14:59 +0900 Received: from BPXM23GP.gisp.nec.co.jp ([10.38.151.215]) by BPXC24GP.gisp.nec.co.jp ([10.38.151.152]) with mapi id 14.03.0319.002; Wed, 7 Feb 2018 10:14:58 +0900 From: Naoya Horiguchi To: Punit Agrawal CC: "linux-mm@kvack.org" , Andrew Morton , Michal Hocko , Mike Kravetz , "Aneesh Kumar K.V" , Anshuman Khandual , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] mm: hwpoison: disable memory error handling on 1GB hugepage Thread-Topic: [PATCH v2] mm: hwpoison: disable memory error handling on 1GB hugepage Thread-Index: AQHTnu0gPYXLibQ98UmzH7feYbNX3qOXjWiA Date: Wed, 7 Feb 2018 01:14:57 +0000 Message-ID: <20180207011455.GA15214@hori1.linux.bs1.fc.nec.co.jp> References: <20180130013919.GA19959@hori1.linux.bs1.fc.nec.co.jp> <1517284444-18149-1-git-send-email-n-horiguchi@ah.jp.nec.com> <87inbbjx2w.fsf@e105922-lin.cambridge.arm.com> In-Reply-To: <87inbbjx2w.fsf@e105922-lin.cambridge.arm.com> Accept-Language: en-US, ja-JP Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.128.101.10] Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <6B62D0280E0A10418C5802502EDC15BD@gisp.nec.co.jp> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-TM-AS-MML: disable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Punit, On Mon, Feb 05, 2018 at 03:05:43PM +0000, Punit Agrawal wrote: > Naoya Horiguchi writes: > > > Recently the following BUG was reported: > > > > Injecting memory failure for pfn 0x3c0000 at process virtual address 0x7fe300000000 > > Memory failure: 0x3c0000: recovery action for huge page: Recovered > > BUG: unable to handle kernel paging request at ffff8dfcc0003000 > > IP: gup_pgd_range+0x1f0/0xc20 > > PGD 17ae72067 P4D 17ae72067 PUD 0 > > Oops: 0000 [#1] SMP PTI > > ... > > CPU: 3 PID: 5467 Comm: hugetlb_1gb Not tainted 4.15.0-rc8-mm1-abc+ #3 > > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-1.fc25 04/01/2014 > > > > You can easily reproduce this by calling madvise(MADV_HWPOISON) twice on > > a 1GB hugepage. This happens because get_user_pages_fast() is not aware > > of a migration entry on pud that was created in the 1st madvise() event. > > Maybe I'm doing something wrong but I wasn't able to reproduce the issue > using the test at the end. I get - > > $ sudo ./hugepage > > Poisoning page...once > [ 121.295771] Injecting memory failure for pfn 0x8300000 at process virtual address 0x400000000000 > [ 121.386450] Memory failure: 0x8300000: recovery action for huge page: Recovered > > Poisoning page...once again > madvise: Bad address > > What am I missing? The test program below is exactly what I intended, so you did right testing. I try to guess what could happen. The related code is like below: static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end, int write, struct page **pages, int *nr) { ... do { pud_t pud = READ_ONCE(*pudp); next = pud_addr_end(addr, end); if (pud_none(pud)) return 0; if (unlikely(pud_huge(pud))) { if (!gup_huge_pud(pud, pudp, addr, next, write, pages, nr)) return 0; pud_none() always returns false for hwpoison entry in any arch. I guess that pud_huge() could behave in undefined manner for hwpoison entry because pud_huge() assumes that a given pud has the present bit set, which is not true for hwpoison entry. As a result, pud_huge() checks an irrelevant bit used for other purpose depending on non-present page table format of each arch. If pud_huge() returns false for hwpoison entry, we try to go to the lower level and the kernel highly likely to crash. So I guess your kernel fell back the slow path and somehow ended up with returning EFAULT. So I don't think that the above test result means that errors are properly handled, and the proposed patch should help for arm64. Thanks, Naoya Horiguchi > > > --------- >8 --------- > #include > #include > #include > > int main(int argc, char *argv[]) > { > int flags = MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE; > int prot = PROT_READ | PROT_WRITE; > size_t hugepage_sz; > void *hugepage; > int ret; > > hugepage_sz = 1024 * 1024 * 1024; /* 1GB */ > hugepage = mmap(NULL, hugepage_sz, prot, flags, -1, 0); > if (hugepage == MAP_FAILED) { > perror("mmap"); > return 1; > } > > memset(hugepage, 'b', hugepage_sz); > getchar(); > > printf("Poisoning page...once\n"); > ret = madvise(hugepage, hugepage_sz, MADV_HWPOISON); > if (ret) { > perror("madvise"); > return 1; > } > getchar(); > > printf("Poisoning page...once again\n"); > ret = madvise(hugepage, hugepage_sz, MADV_HWPOISON); > if (ret) { > perror("madvise"); > return 1; > } > getchar(); > > memset(hugepage, 'c', hugepage_sz); > ret = munmap(hugepage, hugepage_sz); > if (ret) { > perror("munmap"); > return 1; > } > > return 0; > } >