From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1117C32772 for ; Tue, 23 Aug 2022 21:01:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B3EC6B0073; Tue, 23 Aug 2022 17:01:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2631D6B0074; Tue, 23 Aug 2022 17:01:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12AC1940007; Tue, 23 Aug 2022 17:01:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 042F56B0073 for ; Tue, 23 Aug 2022 17:01:47 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C9E95AC149 for ; Tue, 23 Aug 2022 21:01:46 +0000 (UTC) X-FDA: 79832079012.06.0D1384E Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) by imf01.hostedemail.com (Postfix) with ESMTP id 6EBD640037 for ; Tue, 23 Aug 2022 21:01:46 +0000 (UTC) Received: by mail-vs1-f47.google.com with SMTP id k10so10619491vsr.4 for ; Tue, 23 Aug 2022 14:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=pO7ZqfRiAmnavkU8GmZ06Kcz4TLBMS10b+H3mC3wfmU=; b=OVGYBmdyPJ8RRrVeNjcQD3+Vq4FTxBUG+dj4v4VrW40FjbP+uLaK80uyXaHoGi3pYd Nps0IxRCRhlJJZZL66k1c2eYBrBNCZEUz4hLFXZbXNFnBXZT7l8orRKsAS3lAF4JO8rp abCtDO2uJepmv+wMMo/k4GcRE9k7pNRdYcTE7J6eKAg3zM5U5gYUMkfJQXly/WbI7Ct2 TjqPyvCZZGPgfy9hT9rrNaYN5w8S4eiuiA8yVOht4sObJnUWJ4tVWH6BWeKgItVpp+CX RbwZMUP/ee+xhz1KPgTOblF3/wQ2aDRQEYvoDa5VoH4llMnXfYNacxwq5/0SN7sCxGUp Zxjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=pO7ZqfRiAmnavkU8GmZ06Kcz4TLBMS10b+H3mC3wfmU=; b=QacM16zkFxPkY+lEi6glSX49EO4SYTZrx3Anu+zC5k3DoQBaqQK+6KPMoYQ2ZU8JUR AkLFoh4eGafT6fYMV0/0FdTTfEqOb+hyWL3BMjYNiSmBZL9Us1k1b60IBJ5j7eS1Q3oj qMq8keN94eWN4RMJuZjkDxu+h5Mv9tj0sGOzHdoF0ZaV5JcRqopb7LP6t+OVyboKdn5Z Kl70lXfKC+2pp7/STSpPPg6OXbJNiiYp4cy8Vg9jTTfEnBsfdLOovzQ4HZjbweaudasQ 6ZZSnyCv8PB6dtWrAqN/2xWzvRHM+kMxtXD21kJ/oO28RLrj2m9iJVOWrXRknSDK06gT SNrA== X-Gm-Message-State: ACgBeo3ePbCsPxluPjMuN1IO8CtvqB8A5cjGDNrWFzZmUPC1sb8qsvUM zbygCbIkAhgLvrSp1rGwPJsCamwvTsEur9T3czj4uw== X-Google-Smtp-Source: AA6agR61EaCs5pkD4JW0vpgV7j5D9H/ME8bnIG4kRzC8Mj9moq2yJIOm6N7SLV6Cl5LVKp8JI2qh5mo1Jz1pHeGfqkk= X-Received: by 2002:a05:6102:3005:b0:390:5c54:7aea with SMTP id s5-20020a056102300500b003905c547aeamr4855722vsa.50.1661288505413; Tue, 23 Aug 2022 14:01:45 -0700 (PDT) MIME-Version: 1.0 References: <20220811161331.37055-1-peterx@redhat.com> <20220811161331.37055-4-peterx@redhat.com> <87lerudwcb.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87lerudwcb.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yu Zhao Date: Tue, 23 Aug 2022 15:01:09 -0600 Message-ID: Subject: Re: [PATCH v4 3/7] mm/swap: Add swp_offset_pfn() to fetch PFN from swap entry To: Peter Xu , Andrew Morton Cc: "Huang, Ying" , Linux-MM , linux-kernel , Hugh Dickins , "Kirill A . Shutemov" , Alistair Popple , Andrea Arcangeli , Minchan Kim , David Hildenbrand , Andi Kleen , Nadav Amit , Vlastimil Babka Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661288506; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pO7ZqfRiAmnavkU8GmZ06Kcz4TLBMS10b+H3mC3wfmU=; b=SgkGyKUL3beaqujVRvepRUBdYkXNpTC3sVGo95Fw+JPHEMrPsGsB70HXf5HSXdBIPqN5Ik D3yvtu66bbaQhEjR7PuZBU8RoV+CHQgemM/2v5Nq13+aS4Ii/M7YI2KotkLN+jnaXJxDP0 jQKaE8F7pguuIUiyL1/gvJhdWYPUp0U= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OVGYBmdy; spf=pass (imf01.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.47 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661288506; a=rsa-sha256; cv=none; b=Hs8Cqmmj9cMi2gn+xli0oLDAQO9UejktPFMF/61FUPUkwn2QT753TUyv1T+lMKyqTVma7k 5WZBeaxOyIGy2zghJb/hWkHGhhrkE7Bz3rLfYK9VtwV8fzyw8wi7mUOe3r7JKLi6hPbAU6 oIMs9oo9J49kotr+UONRwqd/m+kW9FM= X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OVGYBmdy; spf=pass (imf01.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.47 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6EBD640037 X-Stat-Signature: agmp883ui7r4bsebptdoaghdunpf5tea X-HE-Tag: 1661288506-640778 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: On Thu, Aug 11, 2022 at 8:33 PM Huang, Ying wrote: > > Peter Xu writes: > > > We've got a bunch of special swap entries that stores PFN inside the swap > > offset fields. To fetch the PFN, normally the user just calls swp_offset() > > assuming that'll be the PFN. > > > > Add a helper swp_offset_pfn() to fetch the PFN instead, fetching only the > > max possible length of a PFN on the host, meanwhile doing proper check with > > MAX_PHYSMEM_BITS to make sure the swap offsets can actually store the PFNs > > properly always using the BUILD_BUG_ON() in is_pfn_swap_entry(). > > > > One reason to do so is we never tried to sanitize whether swap offset can > > really fit for storing PFN. At the meantime, this patch also prepares us > > with the future possibility to store more information inside the swp offset > > field, so assuming "swp_offset(entry)" to be the PFN will not stand any > > more very soon. > > > > Replace many of the swp_offset() callers to use swp_offset_pfn() where > > proper. Note that many of the existing users are not candidates for the > > replacement, e.g.: > > > > (1) When the swap entry is not a pfn swap entry at all, or, > > (2) when we wanna keep the whole swp_offset but only change the swp type. > > > > For the latter, it can happen when fork() triggered on a write-migration > > swap entry pte, we may want to only change the migration type from > > write->read but keep the rest, so it's not "fetching PFN" but "changing > > swap type only". They're left aside so that when there're more information > > within the swp offset they'll be carried over naturally in those cases. > > > > Since at it, dropping hwpoison_entry_to_pfn() because that's exactly what > > the new swp_offset_pfn() is about. > > > > Signed-off-by: Peter Xu > > LGTM, Thanks! > > Reviewed-by: "Huang, Ying" Hi, I hit the following crash on mm-everything-2022-08-22-22-59. Please take a look. Thanks. kernel BUG at include/linux/swapops.h:117! CPU: 46 PID: 5245 Comm: EventManager_De Tainted: G S O L 6.0.0-dbg-DEV #2 RIP: 0010:pfn_swap_entry_to_page+0x72/0xf0 Code: c6 48 8b 36 48 83 fe ff 74 53 48 01 d1 48 83 c1 08 48 8b 09 f6 c1 01 75 7b 66 90 48 89 c1 48 8b 09 f6 c1 01 74 74 5d c3 eb 9e <0f> 0b 48 ba ff ff ff ff 03 00 00 00 eb ae a9 ff 0f 00 00 75 13 48 RSP: 0018:ffffa59e73fabb80 EFLAGS: 00010282 RAX: 00000000ffffffe8 RBX: 0c00000000000000 RCX: ffffcd5440000000 RDX: 1ffffffffff7a80a RSI: 0000000000000000 RDI: 0c0000000000042b RBP: ffffa59e73fabb80 R08: ffff9965ca6e8bb8 R09: 0000000000000000 R10: ffffffffa5a2f62d R11: 0000030b372e9fff R12: ffff997b79db5738 R13: 000000000000042b R14: 0c0000000000042b R15: 1ffffffffff7a80a FS: 00007f549d1bb700(0000) GS:ffff99d3cf680000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000440d035b3180 CR3: 0000002243176004 CR4: 00000000003706e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: change_pte_range+0x36e/0x880 change_p4d_range+0x2e8/0x670 change_protection_range+0x14e/0x2c0 mprotect_fixup+0x1ee/0x330 do_mprotect_pkey+0x34c/0x440 __x64_sys_mprotect+0x1d/0x30