Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755705Ab1EIWQD (ORCPT ); Mon, 9 May 2011 18:16:03 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:50390 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750997Ab1EIWP6 (ORCPT ); Mon, 9 May 2011 18:15:58 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Linus Torvalds Date: Mon, 9 May 2011 15:07:41 -0700 Message-ID: Subject: Re: [PATCH] Don't mlock guardpage if the stack is growing up To: Mikulas Patocka , Tony Luck , Fenghua Yu Cc: Hugh Dickins , linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, Michel Lespinasse , Oleg Nesterov , linux-ia64@vger.kernel.org Content-Type: multipart/mixed; boundary=0016e6d58af1b884e304a2df1234 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8263 Lines: 141 --0016e6d58af1b884e304a2df1234 Content-Type: text/plain; charset=ISO-8859-1 On Mon, May 9, 2011 at 8:57 AM, Linus Torvalds wrote: > > Hmm. One thing that strikes me is this problem also implies that the > /proc/self/maps file is wrong for the GROWSUP case, isn't it? > > So I think we should not just apply your lock fix, but then *also* > apply something like this: Actually, I think we might be better off with something like this. It makes a few more changes: - move the stack guard page checking in __get_user_pages() into the rare case (ie we didn't find a page), since that's the only case we care about (the thing about the guard page is that don't want to call "handle_mm_fault()"). As a result, it's off any path where we can possibly care about performance, so we might as well have a nice helper function for both the grow-up and grow-down cases, instead of trying to be clever and only look at the grow-down case for the first page in the vma like you did in your patch. End result: simpler, more straightforward code. - Move the growsup/down helper functions to , since the /proc code really wants to use them too. That means that the "vma_stack_continue()" function (which now got split up into two cases, for the up/down cases) is now entirely just an internal helper function - nobody else uses it, and the real interface are the "stack_guard_page_xyz()" functions. Renamed to be simpler. - changed that naming of those stack_guard_page functions to use _start and _end instead of growsup/growsdown, since it actually takes the start or the end of the page as the argument (to match the semantics of the afore-mentioned helpers) - and finally, make /proc//maps use these helpers for both the up/down case, so now /proc/self/maps should work well for the growsup case too. Hmm? The only oddish case is IA64 that actually has a stack that grows *both* up and down. That means that I could make up a stack mapping that has a single virtual page in it, that is both the start *and* the end page. Now /proc/self/maps would actually show such a mapping with "negative" size. That's interesting. It would be easy enough to have a "if (end < start) end = start" there for that case, but maybe it's actually interesting information. Regardless, I'd like to hear whether this patch really does work on PA-RISC and especially IA64. I think those are the only cases that have a GROWSUP stack. And the IA64 case that supports both is the most interesting, everybody else does just one or the other. Linus --0016e6d58af1b884e304a2df1234 Content-Type: text/x-patch; charset=US-ASCII; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gnhyom1j0 IGZzL3Byb2MvdGFza19tbXUuYyB8ICAgMTIgKysrKysrKy0tLS0tCiBpbmNsdWRlL2xpbnV4L21t LmggfCAgIDI0ICsrKysrKysrKysrKysrKysrKysrKysrLQogbW0vbWVtb3J5LmMgICAgICAgIHwg ICAxNiArKysrKysrLS0tLS0tLS0tCiAzIGZpbGVzIGNoYW5nZWQsIDM3IGluc2VydGlvbnMoKyks IDE1IGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2ZzL3Byb2MvdGFza19tbXUuYyBiL2ZzL3By b2MvdGFza19tbXUuYwppbmRleCAyZTdhZGRmZDk4MDMuLjMxOGQ4NjU0OTg5YiAxMDA2NDQKLS0t IGEvZnMvcHJvYy90YXNrX21tdS5jCisrKyBiL2ZzL3Byb2MvdGFza19tbXUuYwpAQCAtMjE0LDcg KzIxNCw3IEBAIHN0YXRpYyB2b2lkIHNob3dfbWFwX3ZtYShzdHJ1Y3Qgc2VxX2ZpbGUgKm0sIHN0 cnVjdCB2bV9hcmVhX3N0cnVjdCAqdm1hKQogCWludCBmbGFncyA9IHZtYS0+dm1fZmxhZ3M7CiAJ dW5zaWduZWQgbG9uZyBpbm8gPSAwOw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pZiAoc3RhY2tfZ3VhcmRfcGFnZSh2bWEsIHN0YXJ0KSkKKwkJ CQkJCWdvdG8gbmV4dF9wYWdlOworCQkJCX0KIAkJCQlpZiAoZm9sbF9mbGFncyAmIEZPTExfV1JJ VEUpCiAJCQkJCWZhdWx0X2ZsYWdzIHw9IEZBVUxUX0ZMQUdfV1JJVEU7CiAJCQkJaWYgKG5vbmJs b2NraW5nKQo= --0016e6d58af1b884e304a2df1234-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/