Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp486466lqt; Mon, 18 Mar 2024 13:50:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyA/fQHLxmQEXEpxhJZiavsi3vtuoWlugIEFS5/WXvevgANPF2kS7ArFbt/FunzmOysx8FVVU70CFWfDP+X7S783aCNvTMQaFiNJ3vdw== X-Google-Smtp-Source: AGHT+IH1AGxVaN+OONxc/65z1TtZ9I8VqVssmwqjw3ftYUkZoHGnAQZjjOnlDfJjzWbKCiCTK5IR X-Received: by 2002:a05:6402:4590:b0:567:e6c:c60f with SMTP id ig16-20020a056402459000b005670e6cc60fmr567131edb.16.1710795051975; Mon, 18 Mar 2024 13:50:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710795051; cv=pass; d=google.com; s=arc-20160816; b=q4Yxd7D+uK90t3bLaqR2Zg7C7mfDFWvO5S9o/VAh7kEBfrs+l6nGCtWpOjrd7YtYGO +6u5qM4M36si+gC7ctcute0Ie8mIaqpvyref1H/Dhw/dYWzyTc8lDxSd7rnwPZqbpQOT GG3xJxWN8iYo6T3Hn7ZUxWQzVA2vLWdQFQvqDDpvHGoEPyBxmNUwhGy3+ghdqtk4wr98 4crJS4tpW/GKavTpA8zIdEQ+AEU8PpiB12mPOWKl2iCfRkIE7YLwfwYTGOeCiPQXYE+5 RVNZ/1ywlp+t+ltTAKkwUkerMDKYOJw92eItA0cIT1zie24R46GjUgetZEesYWZlL2Gb p7og== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=aInPZU8ZCi7iEM6SQv8qrjNGFrnU4zLmzqDSDyV+MFA=; fh=AlD3n8rypI1cYewHt+/nYOnOeiyXgu5ZzibSHDgU3go=; b=AlRcI+db/XXuVpd3FjJFzJfZ0NbW724jlI5/CiG7yyid7KjR84bED/DFcvlz8GJ3Ox nalosRN/h5sO69kN0Lkja4h6DpcSAsOw2zqU+n9ZNCePfLP6RgVlNC+H52RJtea6ctNx ydLnxAWD6uJ0XZP7m+hHJX7xJIQD/YNJkUIog0l/NNe7+g9GJa8Tl8GgzVWovs7fLi8k 1lwmNkH52F3KlRHXzl7Scqhnz55ItOSdWwmSs1Db3azdHXCwcj8O/xz8WZaiDzDCNRhM OzIL8vEIXYA9TK+/gRf3dBUc5175ltQS6X6iD+ZBmYKjFJ8yNRrUnUq/tpuO1sNSEp38 wP/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=egwKstfS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-106653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ef14-20020a05640228ce00b005685eaa2e00si4973683edb.450.2024.03.18.13.50.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 13:50:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=egwKstfS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-106653-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8759C1F2178B for ; Mon, 18 Mar 2024 20:50:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D82256742; Mon, 18 Mar 2024 20:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="egwKstfS" Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 925A1250EC for ; Mon, 18 Mar 2024 20:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710795045; cv=none; b=ccpKdBIiQfiKjstJbDn9NCX89A+GTyq8J6keFxlzOMhUZDs/jaS9MZDb3fLjbQWa54aP4O1n46c77TDBf/xh+rBvQjR+KrmGB1vgmVV/pvFDv5+g+5xYUJiv+DWJPAkAF6kyoJgYpBd9+Cs32mL8bnrItnH2v+eE3K9MuZW+L48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710795045; c=relaxed/simple; bh=tzDzOD9lG0PFz/q/x2y7h3krtiV/OfjUp7kHu+v2Qko=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OJpMEwRuDKOnO/zByttENMreIhvVFEr98VqTMWXwI+dfSB6WH3dKAgfkK1UPme+i3znFbh+IS2niAMCyBp426bN1x3K9fYWLCrlug40e/3VvnzbWau75BSmRyeNvlaJ/zu1bWEh51Ty9p0KudiYFcId49eocl0B5F6CWqcTHW9Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=egwKstfS; arc=none smtp.client-ip=209.85.217.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-475ffc62cbaso1164669137.1 for ; Mon, 18 Mar 2024 13:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710795042; x=1711399842; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aInPZU8ZCi7iEM6SQv8qrjNGFrnU4zLmzqDSDyV+MFA=; b=egwKstfSBoF51PYsDhx1whXehLSbKDty9POI9A1Fvvqw1YfJjT8Cr/I38iKtNjkY8X cZpxgLUqbTiN+/HPqthVuLk1YxlTwIaKSCdIGSGOCNu6RbYl7mJX5ebt72RQJn/7ICu1 2i9KoqoKFefGfEU+7dkaBQq0/lacRFleknwOFwkmgBl2A8OnCYC0jPHEp06D2NpNKs/H OlqT3E6BIug37Get1MKdm7E20+fGyH4EAzYO4qHUtSVsdmgxu10ECHxF5GOUgaMjnFp9 LJuXO0v1c5k4FDWZXldzyKaLXQ0eHPgtvhttb76LfKNNySz238q1KUipGiePPsqXJ1qO E+/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710795042; x=1711399842; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aInPZU8ZCi7iEM6SQv8qrjNGFrnU4zLmzqDSDyV+MFA=; b=vrXBlxY+9JN0Zzc2JYqT8Za8V9eaWBEugcBXFE6UOiFekv5lsaoiPjK2H/HV040kxw BX8nBknCICeSCo4+5saB+aRzhc7crrE+5TzwMCUadhGqQ1jtTqMy6yLlDRqrkeloQwea VSUCMkh2oEgt7zJrTM7pPaE/B9pLMDsw34R29lTIH2XrmYauglHb/Cn5eVlDF1y78LDL RV9kDRRVhYgkDCQZ6vxW7vExngQRtfKVV9eMkP2kIJJHJDmKUwN+kYqBxewozUES2Ruu Fo6S3H/yDtk94KsZXSDnQijcamEe2p2xLAnkvebIESoBbzisnXeSGSfVwf7Ze/J1RknV 9Pnw== X-Forwarded-Encrypted: i=1; AJvYcCWqIcOA2skxosD1n4ggD0/GASl51DaDjgIes0PPB5sguBdpI9rofR4dbSUZKsHNWaqRSey15tSWU53FmlJYAzQ3lweEPW0CHl4GsKMq X-Gm-Message-State: AOJu0Yxq8jzaHZG9p3y5PcS1A/UQRWqS7tW4WDy8mcpPGdaUL56PYo+1 pqVgErookVbItdYl0wTI1u/xFL0Em791YQ4hv3k0jYZdoa76c48tcz7QVHrMVXKBW0msKH3PTPj 5u01cVhPVL0EG6wkFmHXE7enQrno= X-Received: by 2002:a67:fc81:0:b0:476:9b54:506b with SMTP id x1-20020a67fc81000000b004769b54506bmr510050vsp.5.1710795042387; Mon, 18 Mar 2024 13:50:42 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <000000000000bbb3d80613f243a6@google.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 19 Mar 2024 09:50:30 +1300 Message-ID: Subject: Re: [syzbot] [mm?] kernel BUG in sg_init_one To: Yosry Ahmed Cc: Nhat Pham , syzbot , akpm@linux-foundation.org, chengming.zhou@linux.dev, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Barry Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 19, 2024 at 9:35=E2=80=AFAM Yosry Ahmed = wrote: > > On Mon, Mar 18, 2024 at 1:25=E2=80=AFPM Barry Song <21cnbao@gmail.com> wr= ote: > > > > On Tue, Mar 19, 2024 at 7:00=E2=80=AFAM Nhat Pham w= rote: > > > > > > On Mon, Mar 18, 2024 at 9:58=E2=80=AFAM syzbot > > > wrote: > > > > > > > > Hello, > > > > > > > > syzbot found the following issue on: > > > > > > > > HEAD commit: e5eb28f6d1af Merge tag 'mm-nonmm-stable-2024-03-14-= 09-36' .. > > > > git tree: upstream > > > > console output: https://syzkaller.appspot.com/x/log.txt?x=3D13043ab= e180000 > > > > kernel config: https://syzkaller.appspot.com/x/.config?x=3D19bb57c= 23dffc38e > > > > dashboard link: https://syzkaller.appspot.com/bug?extid=3Dadbc983a1= 588b7805de3 > > > > compiler: arm-linux-gnueabi-gcc (Debian 12.2.0-14) 12.2.0, GN= U ld (GNU Binutils for Debian) 2.40 > > > > userspace arch: arm > > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=3D1706d= 231180000 > > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=3D13ba795= 9180000 > > > > > > > > Downloadable assets: > > > > disk image (non-bootable): https://storage.googleapis.com/syzbot-as= sets/8ead8862021c/non_bootable_disk-e5eb28f6.raw.xz > > > > vmlinux: https://storage.googleapis.com/syzbot-assets/0a7371c63ff2/= vmlinux-e5eb28f6.xz > > > > kernel image: https://storage.googleapis.com/syzbot-assets/7539441b= 4add/zImage-e5eb28f6.xz > > > > > > > > IMPORTANT: if you fix the issue, please add the following tag to th= e commit: > > > > Reported-by: syzbot+adbc983a1588b7805de3@syzkaller.appspotmail.com > > > > > > > > ------------[ cut here ]------------ > > > > kernel BUG at include/linux/scatterlist.h:187! > > > > > > Looks like the provided buffer is invalid: > > > > > > #ifdef CONFIG_DEBUG_SG > > > BUG_ON(!virt_addr_valid(buf)); > > > #endif > > > > > > which is "src" from: > > > > > > sg_init_one(&input, src, entry->length); > > > > > > Looking at the surrounding code and recent history, there's this > > > commit that stands out: > > > > > > mm/zswap: remove the memcpy if acomp is not sleepable > > > (sha: 270700dd06ca41a4779c19eb46608f076bb7d40e) > > > > > > which has the effect of, IIUC, using the zpool mapped memory directly > > > as src, instead of acomp_ctx->buffer (which was previously the case, > > > as zsmalloc was not sleepable). > > > > > > This might not necessarily be a bug with that commit itself, but migh= t > > > have revealed another bug elsewhere. > > > > > > Anyway, cc-ing the author, Barry Song, to fact check me :) Will take = a > > > closer look later. > > > > I guess that is because on arm32 , we have highmem but > > sg_init_one supports lowmem only. the below should be > > able to fix? > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index 9dec853647c8..47c0386caba2 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -1086,7 +1086,8 @@ static void zswap_decompress(struct zswap_entry > > *entry, struct page *page) > > zpool_unmap_handle(zpool, entry->handle); > > } > > > > - sg_init_one(&input, src, entry->length); > > + sg_init_table(&input, 1); > > + sg_set_page(&input, kmap_to_page(src), entry->length, > > offset_in_page(src)); > > Is this working around the debug check in sg_init_one()? IIUC, only I wouldn't characterize it as a workaround; it's more of a solution. > lowmem pages are supported. We may be passing in a highmem page to > sg_set_page() now, right? we can pass highmem to sg_set_page(). This is perfectly fine. > > Also, it seems like if src is a lowmem address kmap_to_page() will be > doing unnecessary checks (assuming it's working correctly)? In practice, we consistently use kmap and kunmap even on systems with low memory. However, it's worth noting that for low memory scenarios, kmap essentially returns page_to_virt(page_address). Thus, the overhead of kmap_to_page shouldn't be significant on low memory systems, especially considering that it simplifie= s to virt_to_page(). Another approach is to consistently employ page_to_virt() for low memory situations and reserve kmap for high memory scenarios. However, since we always utilize kmap regardless of whether the page is low or high memory, we don't need to conc= ern ourselves with this distinction > > Would it be more robust to just use the temporary buffer if src is a > kmap address? I don't think so because we will need a memcpy then. > > Also FWIW, I think you can use "#sys test" to check if a diff fixes the p= roblem. > > > sg_init_table(&output, 1); > > sg_set_page(&output, page, PAGE_SIZE, 0); > > acomp_request_set_params(acomp_ctx->req, &input, &output, > > entry->length, PAGE_SIZE); > > > > > > Thanks Barry