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 0A60CC48BF8 for ; Mon, 19 Feb 2024 11:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 927C76B0074; Mon, 19 Feb 2024 06:36:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D7216B0075; Mon, 19 Feb 2024 06:36:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79EA36B0078; Mon, 19 Feb 2024 06:36:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 676DA6B0074 for ; Mon, 19 Feb 2024 06:36:21 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0E3F24031E for ; Mon, 19 Feb 2024 11:36:21 +0000 (UTC) X-FDA: 81808350162.23.075B40F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf26.hostedemail.com (Postfix) with ESMTP id E243D140012 for ; Mon, 19 Feb 2024 11:36:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=gOkmpw19; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=igtd19NE; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tRUmE+Cn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZckRGqD5; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf26.hostedemail.com: domain of tiwai@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=tiwai@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708342579; 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=++pUqJHlS6MN+oKKOs0BIVMJQQNPqDxn7dbMyMsqdUw=; b=VC/OCCn5Dgc4Xpg8LIZCqnllQ/dH+RPhdW9UDshd16MxaIyOxHUxoOuKn+Nzn8lMqQEy8E 3sF22FWKU295KdoPlid6+pASeuCJlcnb8ZqpBbZXqP4oTexIretjRIoNZN9ofnUKKHKyRa AH3jVh95cph3brkEp3vn1s+DvOIPpL0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=gOkmpw19; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=igtd19NE; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tRUmE+Cn; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZckRGqD5; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf26.hostedemail.com: domain of tiwai@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=tiwai@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708342579; a=rsa-sha256; cv=none; b=FmfYFRn6NA/yq1cMWYAE9/I3fRazjIwJDRG/S7iGJu/OfoRAL6SaS8ROebEYoTCthHJcGH LoQEXEMG/YpyQFBwk2RNGTfhhKq5u4Hw5OTmZSbJ/WXq+/unhruBRVQX78Oy0AieD1NnFO tBLjuVptPo7QGF0+wg7Cw6NoqclIgxI= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D70111FD12; Mon, 19 Feb 2024 11:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708342577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=++pUqJHlS6MN+oKKOs0BIVMJQQNPqDxn7dbMyMsqdUw=; b=gOkmpw19z0RcolN5EFVc39HdeoxMe3gMlPBy8snsKuN4tmu7l5HB3uhAbykbuCj4ChLDpA gVmAlQ/HlOIsl3qgP2WS5pSabK5iBX+voUryLyfTC10GZGR+wosW32N/WIiCMHCpY0h7/L ss1Xwf6RKDivqoWA+juSRbHCNM6teTQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708342577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=++pUqJHlS6MN+oKKOs0BIVMJQQNPqDxn7dbMyMsqdUw=; b=igtd19NEIa2EmtPk2qdNKnFWNQPkvo9dpf7KNVE1LpSYToWiIx8ubxKCSVwBBo4xjfbtA7 N5ameFaJN2hgAgCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708342576; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=++pUqJHlS6MN+oKKOs0BIVMJQQNPqDxn7dbMyMsqdUw=; b=tRUmE+CnP981opXZAwsYl64iaXTTQovDQFgGeoEUIwszZv+cZbSU2V/I04YLCxmdc5PoLn S6TwJVxCOsc7iwRFbWGzi+SKYb9lS36rAdPXwqGxFyToFAVAblSa2JPSuN+r/jM27B+0hW lPMFzV9ISwoHju0d/QWmgO+lS7pAluE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708342576; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=++pUqJHlS6MN+oKKOs0BIVMJQQNPqDxn7dbMyMsqdUw=; b=ZckRGqD5jDJNOFgF3rU02FnT4mfbdm+38yq0HgGvvweKT/k+MlzZsKysJoZC7f3emHI9z0 aJtzJ1lb49sQfZBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7D3BC139D0; Mon, 19 Feb 2024 11:36:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6HgmHTA902XeNQAAD6G6ig (envelope-from ); Mon, 19 Feb 2024 11:36:16 +0000 Date: Mon, 19 Feb 2024 12:36:16 +0100 Message-ID: <87jzn0ofdb.wl-tiwai@suse.de> From: Takashi Iwai To: Karthikeyan Ramasubramanian Cc: LKML , Takashi Iwai , Sven van Ashbrook , Brian Geffon , stable@vger.kernel.org, Curtis Malainey , Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, Vlastimil Babka , linux-mm@kvack.org Subject: Stall at page allocations with __GFP_RETRY_MAYFAIL (Re: [PATCH v1] ALSA: memalloc: Fix indefinite hang in non-iommu case) In-Reply-To: <20240214170720.v1.1.Ic3de2566a7fd3de8501b2f18afa9f94eadb2df0a@changeid> References: <20240214170720.v1.1.Ic3de2566a7fd3de8501b2f18afa9f94eadb2df0a@changeid> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: E243D140012 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: j1u4efo7g7stm6u839axr37ff7akk5aq X-HE-Tag: 1708342578-297517 X-HE-Meta: U2FsdGVkX19NShdVqU8/rVVHSsuGH96FAmzROi3kuIue8UC1Gk1bI/P++0L8DJShOW9jPlV5aXEjf6KKO5BMXhMLiQ5z1De2e5zNTJe/qsnou8tvQwN7z16L6ZUgWxGvJFUWKwlQG4Rrxebr2LOA735gyoNXgHme6xeUq0b2UfUItm9OaUOTSGeIRS/G30TxBYxPkHHBAcrW7Xe93OdPkQYN0PGY5KAlwV6CsvKZHifWy2A1rkPn5Y2TFK08rs3SnNgDtmcb3ORP4+V6Qbx0ON+TjQV0i1fVVQYquaAZaveqSFqPz+8B5U45c9yF6esdoctQcIn8HjI3EQXM8qJvlQmuMlisj82yYWEjsDCd0bu283UK07IeWvG/agFErz/3HUGKcm913Bw+eCDwvMXadrwm2LiWE2o4tIbVbeX9oJgfj2tWx6fghWDgfZ7lZsglo0AQm76nypPJzWnggGKfDOozBgpbd0kWwpvzYhY1SO2niU1nwDxPZLjR6Mnu4JikRPZgr/I01BPxBETFYzwBXDTfajgOaw+LNk4GcYq+PTmcbJ2WidzCXJYXtKSkbonVJ/0OgPiMw0jL+wvqy7nAoHex/hmhpalb+vltpO/FusCYpOAaEo2l7HQ7yrlOVytQafxtmmnoGjnCgLXms+y70193QP5SgAnexj+1Op7lMaTedV+VuwchMyRiv0uRajWck3H9eCUg76KAfwQa0NCSwcxoNBHLd/dh0t3xkLFkrTcEYmksvsJoTBaNziizYM4NTrwS9bJutN7aw4LqM8DdEfsr/lInSdgprzdDb17UGvQLP7FjM00N5+R2TrV4Rf1EffehwshJrTywLqs4kk9a5n7oYtzc3hEam9rOf/ddT4MvXgUQHoFtrAijqfpBK0mxK+E8aifFq0OKsCDHEzvSBMQDGzG2SRNcppe1CqX4MR8cLc2IKGKw4YP4EH9IBYvO95gmlpA3Rb2BnliTD3W 1WQ== 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 Thu, 15 Feb 2024 01:07:25 +0100, Karthikeyan Ramasubramanian wrote: > > Before 9d8e536 ("ALSA: memalloc: Try dma_alloc_noncontiguous() at first") > the alsa non-contiguous allocator always called the alsa fallback > allocator in the non-iommu case. This allocated non-contig memory > consisting of progressively smaller contiguous chunks. Allocation was > fast due to the OR-ing in of __GFP_NORETRY. > > After 9d8e536 ("ALSA: memalloc: Try dma_alloc_noncontiguous() at first") > the code tries the dma non-contig allocator first, then falls back to > the alsa fallback allocator. In the non-iommu case, the former supports > only a single contiguous chunk. > > We have observed experimentally that under heavy memory fragmentation, > allocating a large-ish contiguous chunk with __GFP_RETRY_MAYFAIL > triggers an indefinite hang in the dma non-contig allocator. This has > high-impact, as an occurrence will trigger a device reboot, resulting in > loss of user state. > > Fix the non-iommu path by letting dma_alloc_noncontiguous() fail quickly > so it does not get stuck looking for that elusive large contiguous chunk, > in which case we will fall back to the alsa fallback allocator. > > Note that the iommu dma non-contiguous allocator is not affected. While > assembling an array of pages, it tries consecutively smaller contiguous > allocations, and lets higher-order chunk allocations fail quickly. > > Suggested-by: Sven van Ashbrook > Suggested-by: Brian Geffon > Fixes: 9d8e536d36e7 ("ALSA: memalloc: Try dma_alloc_noncontiguous() at first") > Cc: stable@vger.kernel.org > Cc: Sven van Ashbrook > Cc: Brian Geffon > Cc: Curtis Malainey > Signed-off-by: Karthikeyan Ramasubramanian After chatting with Vlastimil, he recommended to get linux-mm people involved, as basically such a problem shouldn't happen in the page allocator side. So let's widen the audience. To recap the thread: the problem is that dma_alloc_contiguous() call with high order pages and __GFP_FAIL_MAYRETRY leads to indefinite stall. (It was __GFP_NORETRY beforehand.) This looks like the code path with the direct page allocation where no IOMMU is involved. Karthikeyan, Sven, and co: could you guys show the stack trace at the stall? This may give us more clear light. Also, Vlastimil suggested that tracepoints would be helpful if that's really in the page allocator, too. Thanks! Takashi > --- > > sound/core/memalloc.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c > index f901504b5afc1..5f6526a0d731c 100644 > --- a/sound/core/memalloc.c > +++ b/sound/core/memalloc.c > @@ -540,13 +540,18 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size) > { > struct sg_table *sgt; > void *p; > + gfp_t gfp_flags = DEFAULT_GFP; > > #ifdef CONFIG_SND_DMA_SGBUF > if (cpu_feature_enabled(X86_FEATURE_XENPV)) > return snd_dma_sg_fallback_alloc(dmab, size); > + > + /* Non-IOMMU case: prevent allocator from searching forever */ > + if (!get_dma_ops(dmab->dev.dev)) > + gfp_flags |= __GFP_NORETRY; > #endif > sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir, > - DEFAULT_GFP, 0); > + gfp_flags, 0); > #ifdef CONFIG_SND_DMA_SGBUF > if (!sgt && !get_dma_ops(dmab->dev.dev)) > return snd_dma_sg_fallback_alloc(dmab, size); > -- > 2.43.0.687.g38aa6559b0-goog >