Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1150899imm; Wed, 18 Jul 2018 18:12:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeedUzWrwIX8SF3QURIlh89k9Wz5m8Ae+lni/HGGvQsLW7h+yQpxOjH0ha9l1dh0C8brUC5 X-Received: by 2002:a17:902:d70d:: with SMTP id w13-v6mr8117187ply.40.1531962728133; Wed, 18 Jul 2018 18:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531962728; cv=none; d=google.com; s=arc-20160816; b=qSQRRF4HZ9UgPJlV24umujFeJmN75bbR0OYqodaOmvFbpOXBJuZfeozObc+yA6/j2u oSUynDgufxjzEHjILsSboAmRkfXsxmGBTRImaBgaBHJjaGI0hWq8IozYaAc4mCU45zbY u4Vqll0zQ5dx75nPczr2Ob4MMdBfFm62tQi749gOA5gVqukONBhZGh0MgrBj6XLyZduF I+VKSjN+eAOIJaiDiAtVX0sXHgKWWB9Gw2oDra/KxS1yyQFVpAXu6Ey3zDVsg/VkzryA ispRuKUQ5yIUhxPKDZdyFhFCZ7SsAlwYh4S9n2nh0sc47x89+TVwZ0xRFPs0VkZRqi9T Mw1g== 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 :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:arc-authentication-results; bh=D7wNPdkYT7GWvy/UOxRJ9GADjiaGEpkqTTwlLwf64BY=; b=oQFQrkeVqU0CfR1NVWqP0Qpir8+Ce85ILVpsmWrAogmz2hqFso24H4VU7yjf7RdrLg 02JIDL2acrFLa03RoACWj+7lZqchBXHCk4+ag3w2kzoPinHxbhdUrFdUFVNK/5PE5eO+ AaD0iUTB7agnDPoyDAgo5+GJlzc/u9FdYdHeu2iOtZruKs/FIUg+oKulbCP+gkldJ/yG lNUm/QuauT4oM0Vc2b3UwPZjf8bYDNIhlIK6XF+/yHL9SoCQwsOoxt3rfHpifm+yABOH tUi1pf+uSLOtyEkXT+AyBzw0U8t7LfJl0I2A/kwbFVCaVL1qYjIOFQWtE7CYDDEqP66o Zrow== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184-v6si4537134pfe.249.2018.07.18.18.11.52; Wed, 18 Jul 2018 18:12:08 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730600AbeGSBvv convert rfc822-to-8bit (ORCPT + 99 others); Wed, 18 Jul 2018 21:51:51 -0400 Received: from mga11.intel.com ([192.55.52.93]:50578 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729230AbeGSBvv (ORCPT ); Wed, 18 Jul 2018 21:51:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jul 2018 18:11:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,371,1526367600"; d="scan'208";a="57630934" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga007.jf.intel.com with ESMTP; 18 Jul 2018 18:10:06 -0700 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Jul 2018 18:10:05 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Jul 2018 18:10:05 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.81]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.173]) with mapi id 14.03.0319.002; Thu, 19 Jul 2018 09:10:03 +0800 From: "He, Bo" To: Takashi Iwai CC: "alsa-devel@alsa-project.org" , "perex@perex.cz" , "linux-kernel@vger.kernel.org" , "Zhang, Jun" , "Zhang, Yanmin" Subject: RE: [PATCH] ALSA: core: fix unsigned int pages overflow when comapred Thread-Topic: [PATCH] ALSA: core: fix unsigned int pages overflow when comapred Thread-Index: AdQejWjk55iqWVRYS2+apgz1v2Viqv//hmgA//6nsLA= Date: Thu, 19 Jul 2018 01:10:03 +0000 Message-ID: References: In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDQ4YzM1MjQtNWY2OS00ZWI5LTk1OWMtYmQyNGUzYmMyNWUyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiRUtlbytjRjM2Ujlsb1FaUjVEN3ZIcWYzWGh3aUlPZFgrRGthTlRnb1FaUWZEdEJMRitEcHpYT3Z2Rk5PY3RJeiJ9 dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks, we will run the test with your patch, will update the test results in 24 Hours. Current status is: We can reproduce the issue in 3000 cycles stress S/R test, we can't reproduce the kernel panic with our patch in 6000 cycles. -----Original Message----- From: Takashi Iwai Sent: Wednesday, July 18, 2018 8:34 PM To: He, Bo Cc: alsa-devel@alsa-project.org; perex@perex.cz; linux-kernel@vger.kernel.org; Zhang, Jun ; Zhang, Yanmin Subject: Re: [PATCH] ALSA: core: fix unsigned int pages overflow when comapred On Wed, 18 Jul 2018 13:52:45 +0200, He, Bo wrote: > > we see the below kernel panic on stress suspend resume test in > snd_malloc_sgbuf_pages(), snd_dma_alloc_pages_fallback() alloc chunk > maybe larger than the left pages due to the pages alignment, which > will cause the pages overflow. > > while (pages > 0) { > ... > pages -= chunk; > } > > the patch is change the pages from unsigned int to int to fix the issue. Thanks for the patch. Although the analysis is correct, the fix doesn't look ideal. It's also possible that the returned size may over sgbuf->tblsize if we are more unlucky. A change like below should work instead. Could you give it a try? Takashi -- 8< -- --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -108,7 +108,7 @@ void *snd_malloc_sgbuf_pages(struct device *device, break; } chunk = tmpb.bytes >> PAGE_SHIFT; - for (i = 0; i < chunk; i++) { + for (i = 0; i < chunk && pages > 0; i++) { table->buf = tmpb.area; table->addr = tmpb.addr; if (!i) @@ -117,9 +117,9 @@ void *snd_malloc_sgbuf_pages(struct device *device, *pgtable++ = virt_to_page(tmpb.area); tmpb.area += PAGE_SIZE; tmpb.addr += PAGE_SIZE; + sgbuf->pages++; + pages--; } - sgbuf->pages += chunk; - pages -= chunk; if (chunk < maxpages) maxpages = chunk; }