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 C6747C3DA64 for ; Thu, 1 Aug 2024 02:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EE9B6B009C; Wed, 31 Jul 2024 22:37:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19D356B00A2; Wed, 31 Jul 2024 22:37:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03DF76B00A3; Wed, 31 Jul 2024 22:37:31 -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 D34DF6B009C for ; Wed, 31 Jul 2024 22:37:31 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5659A8084D for ; Thu, 1 Aug 2024 02:37:31 +0000 (UTC) X-FDA: 82402115502.15.E3E9A25 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 37A65160008 for ; Thu, 1 Aug 2024 02:37:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GxMIHYkO; spf=pass (imf08.hostedemail.com: domain of jasowang@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722479805; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eCV/gbsqq1NHQ2GSJMetL6TR9fq83KPx+nGrIXful2A=; b=S/4A32UD/aXxgBgkFGGFUDJwiuhhzix4+CJJ0en1kZPwNEp6yCj+B86nGlIhMUGfYEavo3 kOf29bZf9Ya5CHfeSVxdf7yMEidVc9/sjUNyCfzWTkS/BbXIRWdPH8Qt9iFkrfDcnFXXJ/ q6G2OoPpfz5/Kt6TkhgasoXiLjAcpIg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GxMIHYkO; spf=pass (imf08.hostedemail.com: domain of jasowang@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722479805; a=rsa-sha256; cv=none; b=KcNjBaoFJDjgAQ7OAjCqQZZwW7hml3xL4sIKMFV249Y3LcdFIaDsnTDlpP0fD/wuz20SJR VEItRqHNfeZyJBBUK6+sdl3UnzpT/rctIVGjl4tZNQZutA+BOlM/dVy5zvt/kxmGMlUl9N pQTeuJ3juU/L+qLvl5jIcNGVMGgKguA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722479846; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eCV/gbsqq1NHQ2GSJMetL6TR9fq83KPx+nGrIXful2A=; b=GxMIHYkOHZRFgfawI7lIUchLry000tx5wSYgnk3Qh+mRSNRL44BDWkZoIwZWMjZBsRV5Ai EM+mUm9jdxocqLVXYeUMZj7EB/J9QBuV+m+mGSFDUcmtYuNwHRzUd5wdQfibSzrhqLwvQa QhWqfSA15sMdZlp0AStaME43zTIvSRA= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-jPhshB78OjyelrOWq5QKnQ-1; Wed, 31 Jul 2024 22:37:24 -0400 X-MC-Unique: jPhshB78OjyelrOWq5QKnQ-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2cb4bcdd996so1756335a91.1 for ; Wed, 31 Jul 2024 19:37:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722479843; x=1723084643; 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=eCV/gbsqq1NHQ2GSJMetL6TR9fq83KPx+nGrIXful2A=; b=EjR+5AMFTo2jLBj/DKBzEvostTIGMvkmdwXr7L6MuY1qkz+scSCQdmEK5SCz8Bmjh8 vv5JgmZkXMvioArHI3W1I+rPCezuBouaOIkrqYqbnxfII65eg8Or7R2cXvXs9CUHnYi0 j5sT/79mMzskqzZbpo6TcDyj/kqX2fLMEe+sc9YC0gqLmf4Z4IMzv4n+UTj69c3zsOT8 jGttRaQWVTlKss6wX+Y3NFYgbflGOt5fa3wVRDxLCoftHwXPjmSKf4gIDcXPhW4QJ0A1 HdhRYbsWaQs1lbMyQyUwD7ciRtY9U6A9yund3o7XEN+VchD5fQOts/qpVqYcZydluHq8 /T2g== X-Forwarded-Encrypted: i=1; AJvYcCVDH+QjTPw7PUkPyTiidY3bTQtL7nQOhdMYdDQynOwsm8Qri767INklg/SEnsMUJuQMk3vdotvcpA==@kvack.org X-Gm-Message-State: AOJu0YxzxVxGmud0v3X210bGDdF7AsrhvytKJWLzNx+temA4viGCWB+D PyYzx+zXV7TedvqubSy84Z1E4scDeZ7Jt5WfLG3W1p+pz7MHT4IpvViOH1PVYkDALjrwGFfO1Aq HJKaVNnI0iYa5VsYYhyB1FoYmT9KU+hVJ3bzfIx8PDo5uDkw1CpLiZGoAfeDUk0gTBOrcHy6Cdc 2I04eoUs5J2U/zlvEVW1Q3oq8= X-Received: by 2002:a17:90a:bc8a:b0:2c9:5a71:1500 with SMTP id 98e67ed59e1d1-2cfe7da2a1dmr1942691a91.0.1722479843442; Wed, 31 Jul 2024 19:37:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IET7EuEOnpge9cNc1MaYwZg+IDCtIfBL1OyFJpDSCTW8Lj5hFzc/DsOT4Ymou2PsXW7dZFr4cOVKBFljKC9rTY= X-Received: by 2002:a17:90a:bc8a:b0:2c9:5a71:1500 with SMTP id 98e67ed59e1d1-2cfe7da2a1dmr1942651a91.0.1722479842947; Wed, 31 Jul 2024 19:37:22 -0700 (PDT) MIME-Version: 1.0 References: <20240731000155.109583-1-21cnbao@gmail.com> <20240731000155.109583-2-21cnbao@gmail.com> In-Reply-To: From: Jason Wang Date: Thu, 1 Aug 2024 10:37:11 +0800 Message-ID: Subject: Re: [PATCH RFT v2 1/4] vpda: try to fix the potential crash due to misusing __GFP_NOFAIL To: Tetsuo Handa Cc: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, lstoakes@gmail.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, virtualization@lists.linux.dev, "Michael S. Tsirkin" , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Maxime Coquelin X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: gg4yw5df3un1h41mxb16fd77d4oi1bnz X-Rspam-User: X-Rspamd-Queue-Id: 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ZhWqtbtgq5NOx1aURldmfLk7Tv6CO9B1sExcC/pZ7wLILWtig2qX7PHcOaY+sZAucw859ZWEyBL55eLKtxoITZdLtksdyMfVxIvCiofM8SFs6oDWKF0iV8WWskgtK/OdFCYdktC3GUaZ5ARtEA0fMg/VUrs9KBwDoqkPbH6THTRc/MpszVlb9E+OYrtV0TthEylzlod/ZFcFUVAbxchvJoESlbJdKzHrXm9F1/eRPRtKfq+3BTkwbLUbJqrza+LbKCPzMF8BK/IInbdf8WtghoyHfOEb2HXJ1Ey4m39XRiyj0l6FH6p8jkUPcTsb9xZr+ubHA/r7CuANndsurrAeqvDb6HyYK3/e1CFA60xbpBMNNQ5own9Hmgm5am4ewV6jqH2StH2SKbReVDwK2mb3wahBt14iqGS65f317jkTWo/x5GTKZsAKbwxlw== 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: List-Subscribe: List-Unsubscribe: On Wed, Jul 31, 2024 at 6:21=E2=80=AFPM Tetsuo Handa wrote: > > On 2024/07/31 14:05, Barry Song wrote: > > Jason, > > Thank you very much. Also, Tetsuo reminded me that kmalloc_array() migh= t be > > problematic if the count is too large: > > pages =3D kmalloc_array(count, sizeof(*pages), GFP_KERNEL | __GFP_NOFA= IL); > > If "count" is guaranteed to be count <=3D 16, this might be tolerable. It's not unfortunately, the maximum bounce buffer size is: #define VDUSE_MAX_BOUNCE_SIZE (1024 * 1024 * 1024) > > Consider a situation where current thread was chosen as an global OOM vic= tim. > Trying to allocate "count" pages using > > for (i =3D 0; i < count; i++) > pages[i] =3D alloc_page(GFP_KERNEL | __GFP_NOFAIL); > > is not good. Right, I wonder if we need to add a shrink to reclaim the pages that belong to VDUSE bounce pages. > > > > > You might want to consider using vmalloc_array() or kvmalloc_array() in= stead > > when you send a new version. > > There is a limitation at https://elixir.bootlin.com/linux/v6.11-rc1/sourc= e/mm/page_alloc.c#L3033 > that you must satisfy count <=3D PAGE_SIZE * 2 / sizeof(*pages) if you us= e __GFP_NOFAIL. > > But as already explained above, allocating 1024 pages (assuming PAGE_SIZE= is 4096 and > pointer size is 8) when current thread was chosen as an OOM victim is not= recommended. > You should implement proper error handling instead of using __GFP_NOFAIL = if count can > become large. I think I need to consider a way to avoid __GFP_NOFAIL. A easy way is not to free the kernel bounce pages, then we don't need to allocate them again. Thanks > >